add
This commit is contained in:
parent
75b5f001bd
commit
097460a1a4
@ -17,6 +17,9 @@ var init_favour:Dictionary={
|
||||
"test_1":-100,
|
||||
"player":-100,
|
||||
|
||||
},
|
||||
"default":{
|
||||
"default":-60
|
||||
}
|
||||
}
|
||||
#获取初始好感度
|
||||
@ -55,11 +58,28 @@ static var other_unit_data={
|
||||
"hp":100,
|
||||
|
||||
"atk":10,
|
||||
"position":[0,0]
|
||||
}
|
||||
|
||||
|
||||
#角色数据
|
||||
@onready var character_data:Dictionary=pre_proces_data(preload("res://json/character.json").data)
|
||||
func get_unit_data(id:String):
|
||||
func get_unit_data(id:String,as_unit_id:String="default"):
|
||||
if character_data.has(id):
|
||||
return character_data[id].duplicate(true)
|
||||
var res=character_data[id].duplicate(true)
|
||||
res["unit_id"]=as_unit_id
|
||||
return res
|
||||
else:
|
||||
return null
|
||||
|
||||
func get_all_unit_type()->Array:
|
||||
return character_data.keys()
|
||||
|
||||
#地图数据
|
||||
@export var map_data:Dictionary=preload("res://json/map.json").data
|
||||
|
||||
func get_map_data(id:String):
|
||||
if map_data.has(id):
|
||||
return map_data[id]
|
||||
else:
|
||||
return null
|
||||
|
@ -17,6 +17,7 @@ func set_unit_instance(id:String,instance:Node):
|
||||
#获取对象实例
|
||||
func get_unit_instance(id:String):
|
||||
if unit_instance_dic.has(id) and is_instance_valid(unit_instance_dic[id]):
|
||||
|
||||
return unit_instance_dic[id]
|
||||
else:
|
||||
return null
|
||||
@ -49,3 +50,31 @@ func set_unit_favour(self_id:String,other_id:String,favour:float):
|
||||
unit_favour_dic[self_id]={other_id:favour}
|
||||
else:
|
||||
unit_favour_dic[self_id][other_id]=favour
|
||||
|
||||
|
||||
var now_map_id:String="default"
|
||||
var map_dictionary:Dictionary={
|
||||
|
||||
}
|
||||
|
||||
#当前地图是否已经初始化
|
||||
func is_map_initlized(map_id:String):
|
||||
return map_dictionary.has(map_id)
|
||||
|
||||
func add_unit_id_save_map(unit_data:Dictionary):
|
||||
if not unit_data.has("map"):
|
||||
return
|
||||
var map_id=unit_data["map"]
|
||||
if map_id=="default":
|
||||
return
|
||||
var unit_id=unit_data["unit_id"]
|
||||
if map_dictionary.has(map_id):
|
||||
map_dictionary[map_id][unit_id]=unit_data
|
||||
else:
|
||||
map_dictionary[map_id]={
|
||||
unit_id:unit_data
|
||||
}
|
||||
|
||||
#获取地图中的存储角色数据
|
||||
func get_map_data(map_id:String):
|
||||
return map_dictionary[map_id]
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"test_character_base":{
|
||||
"unit_id":"default",
|
||||
"unit_type":"default",
|
||||
"sprite_frames":"res://res/animation/other_character_default.tres",
|
||||
"sprite_offset":[0,-80],
|
||||
@ -11,7 +10,6 @@
|
||||
"attack_scene":"res://scene/character/attack/base/attack_scene_base.tscn",
|
||||
},
|
||||
"test_character_ranged":{
|
||||
"unit_id":"default",
|
||||
"unit_type":"default",
|
||||
"sprite_frames":"res://res/animation/other_character_default.tres",
|
||||
"sprite_offset":[0,-80],
|
||||
|
4
json/map.json
Normal file
4
json/map.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"map_0":"res://scene/map/map_test_0.tscn",
|
||||
"map_1":"res://scene/map/map_test_1.tscn"
|
||||
}
|
@ -6,10 +6,10 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
var all_bodys=unit.sense_area.get_overlapping_bodies()
|
||||
for i in all_bodys:
|
||||
if i is Unit:
|
||||
var favour=Global.get_unit_favour(unit.unit_id,i.unit_id)
|
||||
var favour=Global.get_unit_favour(unit.get_unit_id(),i.get_unit_id())
|
||||
var res=get_res(favour,unit.get_hungry())
|
||||
if res:
|
||||
black_board.set_value("target_unit_id",i.unit_id)
|
||||
black_board.set_value("target_unit_id",i.get_unit_id())
|
||||
return SUCCESS
|
||||
black_board.erase_value("target_unit_id")
|
||||
return FAILURE
|
||||
|
@ -34,7 +34,7 @@ func use_attack_damage():
|
||||
for i in %attack_area.get_overlapping_bodies():
|
||||
print(i)
|
||||
if i is Unit and i!=player():
|
||||
i.attacked(player().unit_id,player().get_atk())
|
||||
i.attacked(player().get_unit_id(),player().get_atk())
|
||||
#if animation.animation in [&"up_attack",&"down_attack",&"left_right_attack"] and not animation.is_playing():
|
||||
#return true
|
||||
#else:
|
||||
|
@ -33,7 +33,7 @@ func use_attack_damage():
|
||||
var new_bullet=ATTACK_RANGE_BULLET.instantiate()
|
||||
new_bullet.global_position=player().global_position
|
||||
new_bullet.global_rotation=global_rotation
|
||||
new_bullet.unit_id=player().unit_id
|
||||
new_bullet.unit_id=player().get_unit_id()
|
||||
new_bullet.atk=player().get_atk()
|
||||
player().get_parent().add_child(new_bullet)
|
||||
|
||||
|
@ -10,6 +10,7 @@ func _ready() -> void:
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
animation_player.play("modulutehide")
|
||||
queue_free()
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
|
1
scene/class/door.gd
Normal file
1
scene/class/door.gd
Normal file
@ -0,0 +1 @@
|
||||
extends Node
|
17
scene/class/map.gd
Normal file
17
scene/class/map.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends Node2D
|
||||
class_name map
|
||||
@export var map_id:String=""
|
||||
|
||||
var pre_character_data:Array=[]
|
||||
func _ready() -> void:
|
||||
Global.now_map_id=map_id
|
||||
for i in get_children():
|
||||
if i is UnitMark2D:
|
||||
var new_dic={
|
||||
"unit_id":i.unit_id,
|
||||
"type":i.unit_type,
|
||||
"unit_data_from_id":i.unit_data_from_id,
|
||||
"position":i.global_position
|
||||
}
|
||||
pre_character_data.append(new_dic)
|
||||
i.queue_free()
|
7
scene/class/unit_mark_2d.gd
Normal file
7
scene/class/unit_mark_2d.gd
Normal file
@ -0,0 +1,7 @@
|
||||
extends Marker2D
|
||||
class_name UnitMark2D
|
||||
@export var unit_id:String=""
|
||||
|
||||
@export var unit_type:String=""
|
||||
|
||||
@export var unit_data_from_id:String=""
|
1
scene/map/map_test_0.gd
Normal file
1
scene/map/map_test_0.gd
Normal file
@ -0,0 +1 @@
|
||||
extends map
|
51
scene/map/map_test_0.tscn
Normal file
51
scene/map/map_test_0.tscn
Normal file
File diff suppressed because one or more lines are too long
46
scene/map/map_test_1.tscn
Normal file
46
scene/map/map_test_1.tscn
Normal file
File diff suppressed because one or more lines are too long
5
scene/mark/character_marker_2d.gd
Normal file
5
scene/mark/character_marker_2d.gd
Normal file
@ -0,0 +1,5 @@
|
||||
@tool
|
||||
extends UnitMark2D
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
%name.text=unit_data_from_id
|
27
scene/mark/character_marker_2d.tscn
Normal file
27
scene/mark/character_marker_2d.tscn
Normal file
@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://b6jyxox72yxjc"]
|
||||
|
||||
[ext_resource type="Script" path="res://scene/mark/character_marker_2d.gd" id="1_6325c"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://jbsg1umeffu1" path="res://res/animation/other_character_default.tres" id="1_rpr3q"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_dhyhy"]
|
||||
outline_size = 6
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Marker2D" type="Marker2D"]
|
||||
script = ExtResource("1_6325c")
|
||||
unit_id = "测试2"
|
||||
unit_type = "default"
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(-2, -88)
|
||||
scale = Vector2(5, 5)
|
||||
sprite_frames = ExtResource("1_rpr3q")
|
||||
animation = &"dead"
|
||||
|
||||
[node name="name" type="Label" parent="."]
|
||||
unique_name_in_owner = true
|
||||
offset_left = -53.0
|
||||
offset_top = -39.0
|
||||
offset_right = 54.0
|
||||
offset_bottom = -16.0
|
||||
label_settings = SubResource("LabelSettings_dhyhy")
|
@ -13,27 +13,7 @@ var action_emoji:Dictionary={
|
||||
"好吃":"😋"
|
||||
}
|
||||
@export var unit_data:Dictionary={
|
||||
"unit_id":"default",
|
||||
"unit_type":"default",
|
||||
#动画资源
|
||||
"sprite_frames":"res://res/animation/other_character_default.tres",
|
||||
#动画偏移
|
||||
"sprite_offset":Vector2(0,-80),
|
||||
#动画缩放
|
||||
"sprite_scale":Vector2(5,5),
|
||||
#基础属性
|
||||
"hp_base":100,
|
||||
"atk_base":10,
|
||||
"speed_base":1,
|
||||
|
||||
|
||||
#攻击方式
|
||||
"attack_type":"base",
|
||||
|
||||
#下面是临时生成的动态数据
|
||||
|
||||
#状态值
|
||||
#饥饿,疲劳,怒气,紧张,恐慌,压力
|
||||
}
|
||||
#允许的状态队列
|
||||
var state_value_array:Array=["hungry","fatigue","rage","tensity","panic","pressure","hp_max","hp","atk"]
|
||||
@ -80,10 +60,14 @@ func set_atk(value):
|
||||
|
||||
|
||||
|
||||
|
||||
##单位的独特ID
|
||||
@export var unit_id:String="default"
|
||||
##单位所属族群
|
||||
@export var unit_type:String="default"
|
||||
|
||||
|
||||
@export var unit_data_from_id:String="default"
|
||||
##每秒触发的timer,用于计算饥饿值积累等
|
||||
var second_timer:Timer
|
||||
@export var animation:AnimatedSprite2D
|
||||
@ -108,7 +92,7 @@ var attack_scene:AttackModel
|
||||
|
||||
#使用数据进行初始化角色
|
||||
func init_from_data():
|
||||
Global.set_unit_instance(unit_id,self)
|
||||
Global.set_unit_instance(get_unit_id(),self)
|
||||
agent.max_speed=unit_speed
|
||||
agent.velocity_computed.connect(safe_speed)
|
||||
second_timer=Timer.new()
|
||||
@ -126,13 +110,19 @@ func init_from_data():
|
||||
new_sprite_animation.position=Vector2(unit_data["sprite_offset"][0],unit_data["sprite_offset"][1])
|
||||
new_sprite_animation.scale=Vector2(unit_data["sprite_scale"][0],unit_data["sprite_scale"][1])
|
||||
animation=new_sprite_animation
|
||||
#攻击模式场景
|
||||
if unit_data.has("attack_scene"):
|
||||
if %rotate!=null:
|
||||
var new_attack_scene=load(unit_data["attack_scene"]).instantiate()
|
||||
%rotate.add_child(new_attack_scene)
|
||||
attack_scene=new_attack_scene
|
||||
Global.unit_instance_dic[get_unit_id()]=self
|
||||
|
||||
|
||||
#改变攻击模式
|
||||
func change_attack():
|
||||
|
||||
|
||||
pass
|
||||
|
||||
#var hungry:float=0:
|
||||
#set(val):
|
||||
@ -140,7 +130,6 @@ func init_from_data():
|
||||
#if %hungry!=null:
|
||||
#%hungry.text="饥饿值:"+str(val)
|
||||
func _ready() -> void:
|
||||
unit_data=Database.get_unit_data("test_character_ranged")
|
||||
init_from_data()
|
||||
pass
|
||||
func set_target_pos(target:Vector2):
|
||||
@ -213,12 +202,12 @@ func accuse(unit_id:String):
|
||||
show_action("指责")
|
||||
var instance=Global.get_unit_instance(unit_id)
|
||||
if instance is UnitOther:
|
||||
instance.accused(self.unit_id)
|
||||
instance.accused(self.get_unit_id())
|
||||
pass
|
||||
#被指责,调用
|
||||
func accused(by_unit_id:String):
|
||||
show_action("被指责")
|
||||
Global.set_unit_favour(unit_id,by_unit_id,Global.get_unit_favour(unit_id,by_unit_id)-10)
|
||||
Global.set_unit_favour(get_unit_id(),by_unit_id,Global.get_unit_favour(get_unit_id(),by_unit_id)-10)
|
||||
pass
|
||||
@export var attack_frames:int=2
|
||||
|
||||
@ -271,7 +260,7 @@ func attack_reset():
|
||||
attack_scene.attack_reset()
|
||||
func attacked(by_unit_id:String,damage:float):
|
||||
show_action("受伤")
|
||||
Global.set_unit_favour(unit_id,by_unit_id,Global.get_unit_favour(unit_id,by_unit_id)-20)
|
||||
Global.set_unit_favour(get_unit_id(),by_unit_id,Global.get_unit_favour(get_unit_id(),by_unit_id)-20)
|
||||
set_state_value("hp",get_state_value("hp")-damage)
|
||||
|
||||
pass
|
||||
@ -321,7 +310,8 @@ func get_dir()->int:
|
||||
func second_timer_time_out():
|
||||
|
||||
set_hungry(clamp(get_hungry()+1,0,100))
|
||||
|
||||
unit_data["position"]=[self.global_position.x,self.global_position.y]
|
||||
unit_data["map"]=Global.now_map_id
|
||||
pass
|
||||
func eat(food:Food):
|
||||
print("吃")
|
||||
@ -337,6 +327,6 @@ func dead():
|
||||
new_dead_scene.global_position=animation.global_position
|
||||
new_dead_scene.scale=animation.scale
|
||||
get_parent().add_child(new_dead_scene)
|
||||
Global.delete_unit_instance(unit_id)
|
||||
Global.delete_unit_instance(get_unit_id())
|
||||
queue_free()
|
||||
pass
|
||||
|
@ -79,6 +79,7 @@ position_smoothing_enabled = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_740ny")
|
||||
disabled = true
|
||||
|
||||
[node name="state_machine" type="Node" parent="."]
|
||||
script = ExtResource("2_v5m4x")
|
||||
|
@ -4,10 +4,10 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
var all_bodys=unit.sense_area.get_overlapping_bodies()
|
||||
for i in all_bodys:
|
||||
if i is Unit and i !=unit:
|
||||
var favour=Global.get_unit_favour(unit.unit_id,i.unit_id)
|
||||
var favour=Global.get_unit_favour(unit.get_unit_id(),i.get_unit_id())
|
||||
var res=get_res(favour,unit.get_hungry())
|
||||
if res:
|
||||
black_board.set_value("target_unit_id",i.unit_id)
|
||||
black_board.set_value("target_unit_id",i.get_unit_id())
|
||||
return SUCCESS
|
||||
return FAILURE
|
||||
pass
|
||||
|
@ -7,7 +7,7 @@ class_name UnitOther
|
||||
func _on_sense_area_body_entered(body: Node2D) -> void:
|
||||
if body is Unit:
|
||||
#自动初始化好感度
|
||||
Global.get_unit_favour(unit_id,body.unit_id)
|
||||
Global.get_unit_favour(get_unit_id(),body.get_unit_id())
|
||||
pass # Replace with function body.
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -138,7 +138,7 @@ texture_under = SubResource("GradientTexture1D_ioncu")
|
||||
texture_progress = SubResource("GradientTexture1D_6t72h")
|
||||
|
||||
[node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")]
|
||||
blackboard = NodePath("@Node@34592")
|
||||
blackboard = NodePath("@Node@223301")
|
||||
actor = NodePath("..")
|
||||
|
||||
[connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"]
|
||||
|
@ -1,7 +1,7 @@
|
||||
extends Unit
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
unit_data=Database.get_unit_data(unit_data_from_id,unit_id)
|
||||
super._ready()
|
||||
state_machine.launch()
|
||||
|
||||
|
@ -4,7 +4,7 @@ extends Node2D
|
||||
func _physics_process(delta: float) -> void:
|
||||
%mouse_finder.position=get_global_mouse_position()
|
||||
|
||||
|
||||
var now_map:map
|
||||
func _on_control_gui_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("mouse_right"):
|
||||
if player:
|
||||
@ -12,6 +12,16 @@ func _on_control_gui_input(event: InputEvent) -> void:
|
||||
|
||||
|
||||
if event.is_action_pressed("mouse_left"):
|
||||
if %put_check.button_pressed:
|
||||
var id=%LineEdit.text
|
||||
var type=selected_item
|
||||
var data=Database.get_unit_data(type,id)
|
||||
var new_cb=load("res://scene/test/other_character.tscn").instantiate()
|
||||
new_cb.unit_data=Database.get_unit_data(type,id)
|
||||
new_cb.global_position=get_global_mouse_position()
|
||||
%CB_add_pos.add_child(new_cb)
|
||||
new_cb.second_timer_time_out()
|
||||
return
|
||||
var arr=%mouse_finder.get_overlapping_bodies()
|
||||
print(arr)
|
||||
if arr.size()==0:
|
||||
@ -38,3 +48,72 @@ func get_closest_node(self_node:Node2D,array:Array,target_class):
|
||||
length=l
|
||||
node=array[i]
|
||||
return node
|
||||
|
||||
func _ready() -> void:
|
||||
var all_types=Database.get_all_unit_type()
|
||||
if all_types.size()>0:
|
||||
selected_item=all_types[0]
|
||||
%type.get_popup().clear()
|
||||
for i in all_types:
|
||||
%type.get_popup().add_item(i)
|
||||
|
||||
%type.get_popup().index_pressed.connect(pop_up_selected)
|
||||
change_map("map_0")
|
||||
var selected_item:String:
|
||||
set(val):
|
||||
selected_item=val
|
||||
%type.text=val
|
||||
func pop_up_selected(index:int):
|
||||
selected_item=%type.get_popup().get_item_text(index)
|
||||
|
||||
|
||||
func _on_cacul_num_number_timeout() -> void:
|
||||
%num.text="场上单位数量:"+str(Global.unit_instance_dic.keys().size())
|
||||
pass # Replace with function body.
|
||||
|
||||
func change_map(map_id:String):
|
||||
if now_map!=null:
|
||||
now_map.queue_free()
|
||||
for i in %CB_add_pos.get_children():
|
||||
if i is UnitOther:
|
||||
Global.delete_unit_instance(i.get_unit_id())
|
||||
Global.add_unit_id_save_map(i.unit_data)
|
||||
|
||||
i.queue_free()
|
||||
|
||||
var new_map_tscn=Database.get_map_data(map_id)
|
||||
if new_map_tscn==null:
|
||||
return
|
||||
var new_map=load(new_map_tscn).instantiate() as map
|
||||
new_map.map_id=map_id
|
||||
add_child(new_map)
|
||||
new_map.z_index-=1
|
||||
now_map=new_map
|
||||
if not Global.is_map_initlized(map_id):
|
||||
var characte_arr=new_map.pre_character_data
|
||||
for i in characte_arr:
|
||||
var new_unit=preload("res://scene/test/other_character.tscn").instantiate()
|
||||
new_unit.unit_data=Database.get_unit_data(i["unit_data_from_id"],i["unit_id"])
|
||||
new_unit.unit_data["type"]=i["type"]
|
||||
new_unit.global_position=i["position"]
|
||||
%CB_add_pos.add_child(new_unit)
|
||||
new_unit.second_timer_time_out()
|
||||
else:
|
||||
var map_character_data=Global.get_map_data(map_id)
|
||||
for i in map_character_data.values():
|
||||
var new_unit=preload("res://scene/test/other_character.tscn").instantiate()
|
||||
new_unit.unit_data=i
|
||||
new_unit.global_position=Vector2(i["position"][0],i["position"][1])
|
||||
%CB_add_pos.add_child(new_unit)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
func _on_change_scene_0_pressed() -> void:
|
||||
change_map("map_0")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_change_scene_1_pressed() -> void:
|
||||
change_map("map_1")
|
||||
pass # Replace with function body.
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user