2024-09-19 12:04:52 +08:00
|
|
|
|
extends Node
|
|
|
|
|
#全局数据json的加载
|
|
|
|
|
var texture_json_path:String="res://json/texture.json"
|
|
|
|
|
var texture_data:Dictionary
|
|
|
|
|
var card_json_path:String="res://json/card.json"
|
|
|
|
|
var card_data:Dictionary
|
|
|
|
|
var script_json_path:String="res://json/script.json"
|
|
|
|
|
var script_data:Dictionary
|
|
|
|
|
var script_type_divide_data:Array=[]
|
|
|
|
|
var event_json_path:String="res://json/event.json"
|
|
|
|
|
var event_data:Dictionary
|
|
|
|
|
var scene_json_path:String="res://json/scene.json"
|
|
|
|
|
var scene_data:Dictionary
|
2024-09-19 17:56:05 +08:00
|
|
|
|
var character_json_path:String="res://json/character.json"
|
|
|
|
|
var character_data:Dictionary
|
2024-09-21 11:52:44 +08:00
|
|
|
|
var map_json_path:String="res://json/map.json"
|
|
|
|
|
var map_data:Dictionary
|
2024-09-23 11:47:55 +08:00
|
|
|
|
|
2024-09-27 17:51:20 +08:00
|
|
|
|
var item_json_path:String="res://json/item.json"
|
|
|
|
|
var item_data
|
|
|
|
|
|
|
|
|
|
|
2024-09-23 11:47:55 +08:00
|
|
|
|
var npc_json_path:String="res://json/npc.json"
|
|
|
|
|
var npc_data:Dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#角色修饰数据的存储路径
|
|
|
|
|
var character_embellish_data_path:String="user://emblish.data"
|
|
|
|
|
var character_embellish_data:Dictionary={
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#加载角色修饰数据(没有则自动创建文件
|
|
|
|
|
func load_character_emblish_data():
|
|
|
|
|
var f=FileAccess.open(character_embellish_data_path,FileAccess.READ)
|
|
|
|
|
if f!=null:
|
|
|
|
|
var data=f.get_var()
|
|
|
|
|
if data is Dictionary:
|
|
|
|
|
character_embellish_data=data.duplicate()
|
|
|
|
|
f.close()
|
|
|
|
|
else:
|
|
|
|
|
f=FileAccess.open(character_embellish_data_path,FileAccess.WRITE)
|
|
|
|
|
f.store_var(character_embellish_data)
|
|
|
|
|
f.close()
|
|
|
|
|
#存储角色修饰数据
|
|
|
|
|
func save_character_embellish_data():
|
|
|
|
|
var f=FileAccess.open(character_embellish_data_path,FileAccess.WRITE)
|
|
|
|
|
f.store_var(character_embellish_data)
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
#添加角色修饰数据
|
|
|
|
|
func add_character_embellich_data(character_id:String,embellish_name:String,data):
|
|
|
|
|
if character_embellish_data.has(character_id):
|
|
|
|
|
character_embellish_data[character_id][embellish_name]=data
|
|
|
|
|
else:
|
|
|
|
|
character_embellish_data[character_id]={
|
|
|
|
|
embellish_name:data
|
|
|
|
|
}
|
|
|
|
|
save_character_embellish_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
2024-09-23 11:47:55 +08:00
|
|
|
|
|
2024-09-19 17:56:05 +08:00
|
|
|
|
var system_config_data:Dictionary={
|
|
|
|
|
|
|
|
|
|
}
|
2024-09-20 17:31:23 +08:00
|
|
|
|
var system_game_data:Dictionary={
|
2024-09-27 17:51:20 +08:00
|
|
|
|
"unlock_character":["test_character_01","test_character_02"],
|
|
|
|
|
#全局物品
|
|
|
|
|
"item":[]
|
2024-09-28 12:04:15 +08:00
|
|
|
|
|
2024-09-20 17:31:23 +08:00
|
|
|
|
}
|
2024-09-28 18:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#获取当前游戏内所有物品
|
|
|
|
|
func get_all_item_game_data()->Array:
|
|
|
|
|
return now_game_data["item"].duplicate(true)
|
|
|
|
|
#根据type获取当前物品
|
|
|
|
|
func get_type_item_game_data(type:int)->Array:
|
|
|
|
|
var item:Array=now_game_data["item"].duplicate(true)
|
|
|
|
|
var res:Array=[]
|
|
|
|
|
for i in item:
|
|
|
|
|
if i.has("type") and int(i["type"])==type:
|
|
|
|
|
res.append(i)
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
func get_now_character_equip_page(page:int):
|
|
|
|
|
return CharacterTool.get_character_equip_page(get_now_character_data(),page)
|
|
|
|
|
|
|
|
|
|
func get_now_character_equip_use():
|
|
|
|
|
return CharacterTool.get_character_equip_now(get_now_character_data())
|
|
|
|
|
|
2024-09-29 11:46:15 +08:00
|
|
|
|
func replace_equip_with_data(page:int,pos:int,item_data):
|
2024-09-28 12:04:15 +08:00
|
|
|
|
|
2024-09-28 18:46:15 +08:00
|
|
|
|
var left=CharacterTool.replace_character_equip(now_game_data["character_data"],page,pos,item_data)
|
|
|
|
|
if left!=null:
|
|
|
|
|
add_item_to_bag(left)
|
2024-09-28 12:04:15 +08:00
|
|
|
|
pass
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#向背包中添加item,会根据allow merger属性决定是否自动合并,并创建num属性
|
|
|
|
|
func add_item_to_bag(item_data:Dictionary):
|
|
|
|
|
var item:Array=now_game_data["item"]
|
|
|
|
|
if item_data["allow_merge"]:
|
|
|
|
|
for i in item_data.size():
|
|
|
|
|
if item_data[i]["id"]==item_data["id"]:
|
|
|
|
|
if item_data[i].has("num"):
|
|
|
|
|
item_data[i]["num"]+=1
|
|
|
|
|
else:
|
|
|
|
|
item_data[i]["num"]=2
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
item.append(item_data)
|
2024-09-29 18:09:09 +08:00
|
|
|
|
|
|
|
|
|
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#根据在背包的排序减少对应物品的数量
|
|
|
|
|
func decrease_item_num_index(ind:int,num:int=1):
|
|
|
|
|
var item:Array=now_game_data["item"]
|
|
|
|
|
if ind<item.size():
|
|
|
|
|
var item_data=item[ind]
|
|
|
|
|
if item_data.has("num"):
|
|
|
|
|
item_data["num"]-=1
|
|
|
|
|
if item_data["num"]<=0:
|
|
|
|
|
item.pop_at(ind)
|
|
|
|
|
else:
|
|
|
|
|
item.pop_at(ind)
|
|
|
|
|
#根据ID减少在背包内的物品
|
|
|
|
|
func decrease_item_num_id(id:String,num:int=1)->bool:
|
|
|
|
|
var item:Array=now_game_data["item"]
|
|
|
|
|
var item_data:Dictionary
|
|
|
|
|
var ind:int
|
|
|
|
|
for i in item.size():
|
|
|
|
|
if item[i]["id"]==id:
|
|
|
|
|
item_data=item[i]
|
|
|
|
|
ind=i
|
|
|
|
|
break
|
|
|
|
|
if item_data==null:
|
|
|
|
|
return false
|
|
|
|
|
else:
|
|
|
|
|
if not item_data.has("num"):
|
|
|
|
|
item_data["num"]=1
|
|
|
|
|
var item_num:int=item_data["num"]
|
|
|
|
|
if item_num>num:
|
|
|
|
|
item_data["num"]-=num
|
|
|
|
|
return true
|
|
|
|
|
elif item_num==num:
|
|
|
|
|
item.pop_at(ind)
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
#通过id获取当前背包数量(如果是不允许合并的物品则返回1(有)或者0(没有))
|
|
|
|
|
func get_item_by_id(id:String)->int:
|
|
|
|
|
var item:Array=now_game_data["item"]
|
|
|
|
|
var item_data:Dictionary
|
|
|
|
|
var ind:int
|
|
|
|
|
for i in item.size():
|
|
|
|
|
if item[i]["id"]==id:
|
|
|
|
|
item_data=item[i]
|
|
|
|
|
ind=i
|
|
|
|
|
break
|
|
|
|
|
if item_data!=null:
|
|
|
|
|
if item_data.has("num"):
|
|
|
|
|
return item_data["num"]
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
2024-09-28 12:04:15 +08:00
|
|
|
|
pass
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#返回一个长度为2的数组,第一个数组存储的item中装备的index,另一个是对应的item_data
|
|
|
|
|
func get_all_equip_index_and_data_in_bag()->Array:
|
|
|
|
|
var item:Array=now_game_data["item"].duplicate(true)
|
|
|
|
|
var res:Array=[]
|
|
|
|
|
var ind_arr:Array=[]
|
|
|
|
|
var data_arr:Array=[]
|
|
|
|
|
for i in item.size():
|
|
|
|
|
if is_item_a_equip(item[i]):
|
|
|
|
|
ind_arr.append(i)
|
|
|
|
|
data_arr.append(item[i])
|
|
|
|
|
res=[ind_arr,data_arr]
|
|
|
|
|
return res
|
2024-09-30 18:06:45 +08:00
|
|
|
|
#返回一个长度为2的数组,第一个数组存储的item中技能的index,另一个是对应的item_data
|
|
|
|
|
func get_all_skill_index_and_data_in_bag()->Array:
|
|
|
|
|
var item:Array=now_game_data["item"].duplicate(true)
|
|
|
|
|
var res:Array=[]
|
|
|
|
|
var ind_arr:Array=[]
|
|
|
|
|
var data_arr:Array=[]
|
|
|
|
|
for i in item.size():
|
|
|
|
|
if is_item_a_skill(item[i]):
|
|
|
|
|
ind_arr.append(i)
|
|
|
|
|
data_arr.append(item[i])
|
|
|
|
|
res=[ind_arr,data_arr]
|
|
|
|
|
return res
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#判断item是否为一个装备(暂时将武器除外)
|
|
|
|
|
func is_item_a_equip(item_data:Dictionary)->bool:
|
2024-09-28 12:04:15 +08:00
|
|
|
|
|
2024-09-28 18:46:15 +08:00
|
|
|
|
if not item_data.has("type"):
|
|
|
|
|
return false
|
|
|
|
|
var type:int=item_data["type"]
|
|
|
|
|
if type in [0,1,2,3]:
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
2024-09-30 18:06:45 +08:00
|
|
|
|
|
|
|
|
|
#判断item是否为一个技能
|
|
|
|
|
func is_item_a_skill(item_data:Dictionary):
|
|
|
|
|
if not item_data.has("type"):
|
|
|
|
|
return false
|
|
|
|
|
var type:int=item_data["type"]
|
|
|
|
|
if type ==6:
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#改变当前角色使用的装备页
|
|
|
|
|
func change_character_equip_now_use(page:int):
|
|
|
|
|
print(page)
|
|
|
|
|
CharacterTool.change_character_equip_now_use(now_game_data["character_data"],page)
|
|
|
|
|
#获取当前使用装备页数
|
|
|
|
|
func get_character_page_now_use()->int:
|
|
|
|
|
return CharacterTool.get_character_equip_now_use_page(now_game_data["character_data"])
|
2024-09-30 18:06:45 +08:00
|
|
|
|
#将角色第ind个技能卡移除,放入背包
|
|
|
|
|
func remove_skill_card_ind_to_bag(ind:int):
|
|
|
|
|
var now_character_data:Dictionary=now_game_data["character_data"]
|
|
|
|
|
var left=CharacterTool.remove_skill_index(now_character_data,ind)
|
|
|
|
|
if left!=null:
|
|
|
|
|
add_item_to_bag(left)
|
|
|
|
|
#将背包中序列为ind的技能卡装备到角色
|
|
|
|
|
func add_sill_card_from_bag_to_character(ind:int):
|
|
|
|
|
var item_data=now_game_data["item"][ind]
|
|
|
|
|
if is_item_a_skill(item_data):
|
|
|
|
|
var res=CharacterTool.add_skill_card(now_game_data["character_data"],item_data)
|
|
|
|
|
if res:
|
|
|
|
|
decrease_item_num_index(ind)
|
|
|
|
|
#获取当前角色的所有技能
|
|
|
|
|
func get_now_character_skill():
|
|
|
|
|
var character_data=now_game_data["character_data"]
|
|
|
|
|
return CharacterTool.get_character_skill_all(character_data)
|
2024-09-28 18:46:15 +08:00
|
|
|
|
##当前数据
|
2024-09-19 17:56:05 +08:00
|
|
|
|
var now_game_data:Dictionary={
|
2024-09-20 17:31:23 +08:00
|
|
|
|
"character_data":{
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
"script_data":{
|
2024-09-20 12:02:11 +08:00
|
|
|
|
|
|
|
|
|
},
|
2024-09-27 17:51:20 +08:00
|
|
|
|
#游戏内物品
|
|
|
|
|
"item":[],
|
2024-09-26 11:49:53 +08:00
|
|
|
|
"now_scene":"",
|
2024-09-20 20:20:14 +08:00
|
|
|
|
"difficulty":0,
|
2024-09-21 11:52:44 +08:00
|
|
|
|
"gold":9999,
|
|
|
|
|
"health":100,
|
2024-09-21 17:51:05 +08:00
|
|
|
|
"spirit":999,
|
2024-09-22 11:48:18 +08:00
|
|
|
|
"map":"map_01",
|
|
|
|
|
"move_ability":1,
|
2024-09-25 18:04:02 +08:00
|
|
|
|
"time_unix":0,
|
|
|
|
|
"card_in_bag":["card_03","card_03","card_02","card_02","card_01","card_01","card_01","card_01"]
|
2024-09-19 17:56:05 +08:00
|
|
|
|
}
|
2024-09-25 18:04:02 +08:00
|
|
|
|
#当前战斗场景
|
|
|
|
|
var now_fight_scene:FightScene
|
|
|
|
|
#向卡组中添加卡牌
|
|
|
|
|
func add_card(card_id:String):
|
|
|
|
|
now_game_data["card_in_bag"].append(card_id)
|
|
|
|
|
#从卡组中删除卡牌
|
|
|
|
|
func delete_card(card_id:String)->bool:
|
|
|
|
|
var now_arr:Array= now_game_data["card_in_bag"]
|
|
|
|
|
var ind=now_arr.find(card_id)
|
|
|
|
|
if ind==-1:
|
|
|
|
|
return false
|
|
|
|
|
else:
|
|
|
|
|
now_game_data["card_in_bag"].pop_at(ind)
|
|
|
|
|
return true
|
2024-09-30 18:06:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var now_fight_enermy_data:Array=[]
|
|
|
|
|
var now_fight_friend_data:Array=[]
|
|
|
|
|
func fight(data:Dictionary):
|
|
|
|
|
if data.has("friend"):
|
|
|
|
|
now_fight_friend_data=data["friend"]
|
|
|
|
|
now_fight_enermy_data
|
|
|
|
|
SceneManager.change_scene_to("res://scene/fight.tscn")
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-26 17:54:02 +08:00
|
|
|
|
#使用卡牌,character为使用者,target为目标,card_data为使用的卡牌数据
|
|
|
|
|
func use_card(card_data:Dictionary,user=null,target=null):
|
2024-09-25 18:04:02 +08:00
|
|
|
|
print("执行了卡牌:\n"+str(card_data)+"\n目标"+str(target))
|
2024-09-26 17:54:02 +08:00
|
|
|
|
if card_data.has("triger"):
|
|
|
|
|
for funcitem in card_data["triger"]:
|
|
|
|
|
var _func=Callable(self,funcitem.func)
|
|
|
|
|
var value:Array=funcitem.value.duplicate()
|
|
|
|
|
for i in value.size():
|
|
|
|
|
if value[i] is String and value[i]=="user":
|
|
|
|
|
value[i]=user
|
|
|
|
|
elif value[i] is String and value[i]=="target":
|
|
|
|
|
value[i]=target
|
|
|
|
|
_func.callv(value)
|
|
|
|
|
##下面是例子
|
|
|
|
|
##打击单位
|
|
|
|
|
func hit(target,value):
|
|
|
|
|
if target is FightCharacterCard ||target is FightEnermyCard:
|
|
|
|
|
target.HP-=value
|
|
|
|
|
#打击全部单位
|
|
|
|
|
func hit_all(value):
|
|
|
|
|
var all_character=now_fight_scene.get_all_unit()
|
|
|
|
|
for i in all_character:
|
|
|
|
|
i.HP-=value
|
|
|
|
|
#回血
|
|
|
|
|
func recover(target,value):
|
|
|
|
|
if target is FightCharacterCard ||target is FightEnermyCard:
|
|
|
|
|
target.HP+=value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-25 18:04:02 +08:00
|
|
|
|
func get_all_card()->Array:
|
|
|
|
|
return now_game_data["card_in_bag"].duplicate()
|
2024-09-22 17:37:51 +08:00
|
|
|
|
func get_move_ability():
|
|
|
|
|
return now_game_data["move_ability"]
|
|
|
|
|
func get_time_dictionary():
|
|
|
|
|
var time_unix=int(now_game_data["time_unix"])
|
|
|
|
|
return Time.get_datetime_dict_from_unix_time(time_unix)
|
2024-09-23 17:27:43 +08:00
|
|
|
|
func get_time_unix():
|
|
|
|
|
return now_game_data["time_unix"]
|
2024-09-22 17:37:51 +08:00
|
|
|
|
#year、month、day、weekday、hour、minute 和 second
|
|
|
|
|
func flow_time(data:Dictionary):
|
|
|
|
|
var date=get_time_dictionary()
|
|
|
|
|
var change_unix:float=0
|
|
|
|
|
if data.has("day"):
|
|
|
|
|
var day=data["year"]
|
|
|
|
|
change_unix+=day*86400
|
|
|
|
|
if data.has("hour"):
|
|
|
|
|
var hour=data["hour"]
|
|
|
|
|
change_unix+=3600*hour
|
|
|
|
|
if data.has("minute"):
|
|
|
|
|
var minute=data["minute"]
|
|
|
|
|
change_unix+=minute*60
|
|
|
|
|
now_game_data["time_unix"]+=change_unix
|
|
|
|
|
time_changed.emit()
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#时间改变的信号
|
2024-09-22 17:37:51 +08:00
|
|
|
|
signal time_changed
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#事件触发器列表
|
2024-09-22 11:48:18 +08:00
|
|
|
|
var triger:Dictionary={
|
|
|
|
|
"change_event":func (data):now_game_flow.show_event(data),
|
|
|
|
|
"change_texture": func (data):now_game_flow.event_panel.change_texture(data),
|
|
|
|
|
"change_text":func(data):now_game_flow.event_panel.change_text(data),
|
|
|
|
|
"change_choice":func(data):now_game_flow.event_panel.change_choice(data),
|
|
|
|
|
"increase_health":func (data):now_game_data.health-=data,
|
2024-09-22 17:37:51 +08:00
|
|
|
|
"end_event":func(data):now_game_flow.event_panel.hide(),
|
2024-09-30 18:06:45 +08:00
|
|
|
|
"flow_time":func (data):flow_time(data),
|
|
|
|
|
"fight":func (data):fight(data)
|
2024-09-22 11:48:18 +08:00
|
|
|
|
}
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#使用事件触发器
|
2024-09-22 11:48:18 +08:00
|
|
|
|
func call_triger(triger_type:String,data):
|
|
|
|
|
if triger.has(triger_type):
|
|
|
|
|
return triger[triger_type].call(data)
|
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#条件触发器(用于返回是否返回条件)
|
2024-09-23 11:47:55 +08:00
|
|
|
|
var condition_triger:Dictionary={
|
2024-09-23 17:27:43 +08:00
|
|
|
|
"date_limit":func (data:Dictionary):return TimeTool.is_in_date(data,get_time_dictionary()),
|
|
|
|
|
"time_limit":func (data:Dictionary):return TimeTool.is_in_time(data,get_time_dictionary()),
|
|
|
|
|
"rand":func (data:Dictionary):return get_rand(data["scene_id"],data["touch_id"],data["index"],data["condition"]),
|
2024-09-23 11:47:55 +08:00
|
|
|
|
|
|
|
|
|
}
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#使用条件触发器
|
2024-09-23 17:27:43 +08:00
|
|
|
|
func call_condition_triger(triger_type:String,data):
|
|
|
|
|
if condition_triger.has(triger_type):
|
|
|
|
|
return condition_triger[triger_type].call(data)
|
|
|
|
|
else:
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
pass
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#记录随机的场景上一次结果,如果时间不变则直接取上一次结果
|
2024-09-23 17:27:43 +08:00
|
|
|
|
var condition_triger_randi_dic:Dictionary={
|
|
|
|
|
"scene_id":{
|
|
|
|
|
"touch_name":{
|
|
|
|
|
"index":{
|
|
|
|
|
"last_time_triger":0000,
|
|
|
|
|
"last_rand_result":false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#同上
|
2024-09-23 17:27:43 +08:00
|
|
|
|
func get_rand(scene_id:String,touch_name:String,index:String,condition:float)->bool:
|
|
|
|
|
if condition_triger_randi_dic.has(scene_id):
|
|
|
|
|
var scene_data=condition_triger_randi_dic[scene_id]
|
|
|
|
|
if scene_data.has(touch_name):
|
|
|
|
|
var touch_data=scene_data[touch_name]
|
|
|
|
|
if touch_data.has(index):
|
|
|
|
|
var triger_data=touch_data[index]
|
|
|
|
|
var last_time_triger=triger_data["last_time_triger"]
|
|
|
|
|
if last_time_triger==get_time_unix():
|
|
|
|
|
return triger_data["last_rand_result"]
|
|
|
|
|
else:
|
|
|
|
|
var dic=recreate_rand_dic(condition)
|
|
|
|
|
condition_triger_randi_dic[scene_id][touch_name][index]=dic
|
|
|
|
|
return dic["last_rand_result"]
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
var dic=recreate_rand_dic(condition)
|
|
|
|
|
condition_triger_randi_dic[scene_id][touch_name][index]=dic
|
|
|
|
|
return dic["last_rand_result"]
|
|
|
|
|
else:
|
|
|
|
|
var dic=recreate_rand_dic(condition)
|
|
|
|
|
condition_triger_randi_dic[scene_id][touch_name]={
|
|
|
|
|
index:dic
|
|
|
|
|
}
|
|
|
|
|
return dic["last_rand_result"]
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
var dic=recreate_rand_dic(condition)
|
|
|
|
|
condition_triger_randi_dic[scene_id]={
|
|
|
|
|
touch_name:{
|
|
|
|
|
index:dic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dic["last_rand_result"]
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#为随机创建一个新的随机字典
|
2024-09-23 17:27:43 +08:00
|
|
|
|
func recreate_rand_dic(condition:float)->Dictionary:
|
|
|
|
|
var new_rand_result:bool=(randf()<condition)
|
|
|
|
|
var dic={
|
|
|
|
|
"last_time_triger":get_time_unix(),
|
|
|
|
|
"last_rand_result":new_rand_result,
|
|
|
|
|
}
|
|
|
|
|
return dic
|
|
|
|
|
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#移动场景,前者是scene的ID,后者是距离当前场景的距离
|
2024-09-22 11:48:18 +08:00
|
|
|
|
func move_scene(scene_id:String,distance):
|
2024-09-22 17:37:51 +08:00
|
|
|
|
if scene_id==get_now_scene():
|
|
|
|
|
return false
|
|
|
|
|
flow_time({
|
|
|
|
|
"minute":distance/get_move_ability()
|
|
|
|
|
})
|
|
|
|
|
now_game_flow.change_scene(scene_id,distance)
|
|
|
|
|
set_now_scene(scene_id)
|
|
|
|
|
return true
|
2024-09-22 11:48:18 +08:00
|
|
|
|
pass
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#获取当前场景ID
|
2024-09-22 11:48:18 +08:00
|
|
|
|
func get_now_scene():
|
|
|
|
|
return now_game_data["now_scene"]
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#设置当前场景,只用于开局重置位置
|
2024-09-22 17:37:51 +08:00
|
|
|
|
func set_now_scene(scene_id:String):
|
|
|
|
|
now_game_data["now_scene"]=scene_id
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#当前的游戏流程场景
|
2024-09-21 11:52:44 +08:00
|
|
|
|
var now_game_flow:GameFlow
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#获取当前角色数据的拷贝
|
2024-09-20 20:20:14 +08:00
|
|
|
|
func get_now_character_data():
|
2024-09-24 11:59:54 +08:00
|
|
|
|
return now_game_data["character_data"].duplicate()
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#设置当前角色(游戏内)
|
|
|
|
|
func set_now_character(id:String):
|
|
|
|
|
now_game_data["character_data"]=get_character_data(id)
|
|
|
|
|
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func _ready() -> void:
|
|
|
|
|
load_texture_data()
|
|
|
|
|
load_script_data()
|
|
|
|
|
load_event_data()
|
|
|
|
|
load_scene_data()
|
2024-09-25 11:52:36 +08:00
|
|
|
|
load_card_data()
|
2024-09-19 17:56:05 +08:00
|
|
|
|
load_character_data()
|
2024-09-22 11:48:18 +08:00
|
|
|
|
load_map_data()
|
2024-09-23 11:47:55 +08:00
|
|
|
|
load_npc_data()
|
2024-09-27 11:47:19 +08:00
|
|
|
|
load_character_emblish_data()
|
2024-09-28 18:46:15 +08:00
|
|
|
|
load_item_data()
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前图片数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func load_texture_data():
|
|
|
|
|
var file=FileAccess.open(texture_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
var texture=load(dictionary[i])
|
|
|
|
|
if texture is Texture2D:
|
|
|
|
|
dictionary[i]=texture
|
|
|
|
|
texture_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前剧本数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func load_script_data():
|
|
|
|
|
var file=FileAccess.open(script_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
script_type_divide_data=[{},{},{},{}]
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
var data=dictionary[i]
|
|
|
|
|
if data.has("type"):
|
|
|
|
|
var type:int=int(data["type"])
|
|
|
|
|
script_type_divide_data[type][i]=data
|
|
|
|
|
script_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前事件数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func load_event_data():
|
|
|
|
|
var file=FileAccess.open(event_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
event_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前场景数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func load_scene_data():
|
|
|
|
|
var file=FileAccess.open(scene_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
scene_data=dictionary
|
|
|
|
|
pass
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前角色数据(未被修饰)
|
2024-09-19 17:56:05 +08:00
|
|
|
|
func load_character_data():
|
|
|
|
|
var file=FileAccess.open(character_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
2024-09-28 18:46:15 +08:00
|
|
|
|
#预处理
|
|
|
|
|
dictionary[i]=CharacterTool.pre_process_character_data(dictionary[i])
|
2024-09-19 17:56:05 +08:00
|
|
|
|
character_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前地图字典
|
2024-09-21 11:52:44 +08:00
|
|
|
|
func load_map_data():
|
|
|
|
|
var file=FileAccess.open(map_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
map_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前NPC数据(可能废弃)
|
2024-09-23 11:47:55 +08:00
|
|
|
|
func load_npc_data():
|
|
|
|
|
var file=FileAccess.open(npc_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
npc_data=dictionary
|
2024-09-27 11:47:19 +08:00
|
|
|
|
#加载当前卡牌数据
|
2024-09-24 11:59:54 +08:00
|
|
|
|
func load_card_data():
|
|
|
|
|
var file=FileAccess.open(card_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
card_data=dictionary
|
|
|
|
|
|
|
|
|
|
pass
|
2024-09-27 17:51:20 +08:00
|
|
|
|
func load_item_data():
|
|
|
|
|
var file=FileAccess.open(item_json_path,FileAccess.READ)
|
|
|
|
|
var str=file.get_as_text()
|
|
|
|
|
var dictionary:Dictionary=JSON.parse_string(str)
|
|
|
|
|
for i in dictionary.keys():
|
|
|
|
|
dictionary[i]["id"]=i
|
|
|
|
|
item_data=dictionary
|
|
|
|
|
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取图标
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func get_texture(id:String):
|
|
|
|
|
if texture_data.has(id):
|
|
|
|
|
return texture_data[id]
|
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取剧本数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func get_script_data(id:String):
|
|
|
|
|
if script_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=script_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-19 12:04:52 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取全部剧本数据,数组
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func get_all_script_data():
|
|
|
|
|
return script_type_divide_data.duplicate()
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取对应ID的事件数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func get_event_data(id:String):
|
|
|
|
|
if event_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=event_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-19 12:04:52 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取对应ID的场景数据
|
2024-09-19 12:04:52 +08:00
|
|
|
|
func get_scene_data(id:String):
|
|
|
|
|
if scene_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=scene_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-19 12:04:52 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取对应ID的角色数据
|
2024-09-19 17:56:05 +08:00
|
|
|
|
func get_character_data(id:String):
|
|
|
|
|
if character_data.has(id):
|
2024-09-27 11:47:19 +08:00
|
|
|
|
var dictionary:Dictionary=character_data[id].duplicate(true)
|
|
|
|
|
#如果有修饰数据,则返回修饰后的数据
|
|
|
|
|
if character_embellish_data.has(id):
|
|
|
|
|
dictionary=CharacterTool.character_embellish(dictionary,character_embellish_data[id])
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-19 17:56:05 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取全部角色数据
|
2024-09-26 17:54:02 +08:00
|
|
|
|
func get_all_character()->Dictionary:
|
2024-09-27 11:47:19 +08:00
|
|
|
|
var all_character:Dictionary=character_data.duplicate(true)
|
|
|
|
|
#修饰数据
|
|
|
|
|
for i in all_character.keys():
|
|
|
|
|
if character_embellish_data.has(i):
|
|
|
|
|
all_character[i]=CharacterTool.character_embellish(all_character[i],character_embellish_data[i])
|
|
|
|
|
return all_character
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取对应ID的地图数据
|
2024-09-21 11:52:44 +08:00
|
|
|
|
func get_map_data(id:String):
|
|
|
|
|
if map_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=map_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-21 11:52:44 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
|
|
|
|
pass
|
2024-09-26 11:49:53 +08:00
|
|
|
|
|
2024-09-23 11:47:55 +08:00
|
|
|
|
func get_npc_data(id:String):
|
|
|
|
|
if npc_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=npc_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-23 11:47:55 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
|
|
|
|
pass
|
2024-09-26 11:49:53 +08:00
|
|
|
|
#获取对应ID的卡牌数据
|
2024-09-24 11:59:54 +08:00
|
|
|
|
func get_card_data(id:String):
|
|
|
|
|
if card_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=card_data[id]
|
2024-09-25 23:56:53 +08:00
|
|
|
|
return dictionary.duplicate(true)
|
2024-09-24 11:59:54 +08:00
|
|
|
|
else:
|
|
|
|
|
return null
|
2024-09-27 17:51:20 +08:00
|
|
|
|
|
|
|
|
|
func get_item_data(id:String):
|
|
|
|
|
if item_data.has(id):
|
|
|
|
|
var dictionary:Dictionary=item_data[id]
|
|
|
|
|
return dictionary.duplicate(true)
|
|
|
|
|
else:
|
|
|
|
|
return null
|