Skip to content

Commit cd9c0c7

Browse files
committed
Zakładanie dusz
1 parent 7fba211 commit cd9c0c7

File tree

12 files changed

+128
-31
lines changed

12 files changed

+128
-31
lines changed

Nodes/UI/InfoLabel.tscn

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
[gd_scene load_steps=4 format=2]
1+
[gd_scene load_steps=5 format=2]
22

33
[ext_resource path="res://Resources/UI/DefaultFont.tres" type="DynamicFont" id=1]
44

5+
[sub_resource type="StyleBoxFlat" id=3]
6+
bg_color = Color( 1, 1, 1, 1 )
7+
58
[sub_resource type="GDScript" id=1]
69
script/source = "extends Panel
710

@@ -28,7 +31,11 @@ func move_down(how_much):
2831
move_down += how_much * 32
2932

3033
func _on_AnimationPlayer_animation_finished(anim_name):
31-
get_parent().free_label(self)"
34+
get_parent().free_label(self)
35+
36+
func set_colors(color, icon_color = Color.white):
37+
self_modulate = color
38+
icon.modulate = icon_color"
3239
3340
[sub_resource type="Animation" id=2]
3441
resource_name = "Disappear"
@@ -52,6 +59,7 @@ anchor_right = 1.0
5259
anchor_bottom = 1.0
5360
margin_left = -387.0
5461
margin_top = -32.0
62+
custom_styles/panel = SubResource( 3 )
5563
script = SubResource( 1 )
5664
5765
[node name="HBoxContainer" type="HBoxContainer" parent="."]

Nodes/UI/SoulItem.tscn

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@
77
[sub_resource type="GDScript" id=1]
88
script/source = "extends HBoxContainer
99

10-
var soul_name
10+
var stack
1111

1212
func set_color(color : Color):
1313
$RightRect/HBoxContainer/Icon.self_modulate = color
1414
$RightRect.self_modulate = color.darkened(0.8)
1515

1616
func set_soul(soul):
17-
soul_name = soul.soul
17+
stack = soul
1818
$RightRect/HBoxContainer/Icon.modulate.a = 1
1919
$RightRect/HBoxContainer/Name.text = soul.soul
2020
$RightRect/HBoxContainer/Amount.text = str(soul.amount)
2121

2222
func clear_soul():
23-
soul_name = null
23+
stack = null
2424
$RightRect/HBoxContainer/Icon.modulate.a = 0
2525
$RightRect/HBoxContainer/Name.text = \"---\"
26-
$RightRect/HBoxContainer/Amount.text = \"\""
26+
$RightRect/HBoxContainer/Amount.text = \"\"
27+
28+
func empty():
29+
return $RightRect/HBoxContainer/Amount.text == \"\""
2730

2831
[node name="SoulItem" type="HBoxContainer"]
2932
margin_right = 157.0

Scripts/Networking/Network.gd

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ signal stats(data)
1818
signal inventory(items)
1919
signal equipment(items)
2020
signal souls(souls)
21+
signal soul_equipment(souls)
2122
signal item_get(item)
2223
signal soul_get(soul)
2324

@@ -170,6 +171,18 @@ func process_packet(unpacker):
170171

171172
emit_signal("souls", souls)
172173

174+
Packet.TYPE.SOUL_EQUIPMENT:
175+
var equipment = []
176+
177+
var equipped = unpacker.get_u8()
178+
for i in 8:
179+
if (equipped & Data.binary[i]):
180+
equipment.append(unpacker.get_u16())
181+
else:
182+
equipment.append(0)
183+
184+
emit_signal("soul_equipment", equipment)
185+
173186
Packet.TYPE.ITEM_GET:
174187
emit_signal("item_get", unpacker.get_u16())
175188

Scripts/Networking/Packet.gd

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ enum TYPE {
1818
INVENTORY,
1919
EQUIPMENT,
2020
SOULS,
21+
SOUL_EQUIPMENT,
2122
EQUIP,
23+
EQUIP_SOUL,
2224
ITEM_GET,
2325
SOUL_GET
2426
}

Scripts/Soul.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const TYPE_COLOR = {
1111
"ability": Color(0, 1, 0),
1212
"mastery": Color(0, 0, 0),
1313
"identity": Color(1, 1, 1)
14-
}
14+
}
1515
const SPEED = 24
1616
const SPEED_SQ = SPEED * SPEED
1717

Scripts/UI/LabelManager.gd

+4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ func push_label(type, data):
2222
var item = Res.get_res(Res.items, data[0])
2323
label.set_text(item.name)
2424
label.set_icon(Res.item_icon(item.name))
25+
label.set_colors(Color.orangered)
2526
SOUL:
2627
var soul = Res.get_res(Res.souls, data[0])
2728
label.set_text(soul.name)
2829
label.set_icon(preload("res://Graphics/Objects/Soul.png"))
30+
31+
var color = Soul.TYPE_COLOR[soul.type]
32+
label.set_colors(color.darkened(0.8), color)
2933

3034
func free_label(label):
3135
label.queue_free()

Scripts/UI/PlayerMenu/PlayerMenu.gd

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func _ready():
2222
Network.connect("inventory", $Container/Tabs/Equipment, "update_equipment_inventory")
2323
Network.connect("equipment", $Container/Tabs/Equipment, "update_equipment")
2424
Network.connect("souls", $Container/Tabs/Souls, "sync_souls")
25+
Network.connect("soul_equipment", $Container/Tabs/Souls, "update_equipment")
2526

2627
for button in buttons.get_children():
2728
button.set_button_group(tab_buttons)

Scripts/UI/PlayerMenu/Souls.gd

+39-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ onready var slots = $Slots
77
onready var inventory = $Inventory
88
onready var description = $Description
99

10+
const SOUL_DESCRIPTIONS = {
11+
"trigger": "Up + Attack to use",
12+
"active": "Shift to activate, either toggled or held",
13+
"augment": "Passive effect on character",
14+
"enchant": "Passive effect on equipment",
15+
"extension": "Passive upgrade on other souls",
16+
"catalyst": "Used for soul forging",
17+
"ability": "Active special abilities",
18+
"mastery": "Powerful permanent abilities",
19+
"identity": "Determines the very essence"
20+
}
21+
1022
var inventory_mode = false
1123
var souls = []
1224
var soul_stacks = {}
@@ -50,6 +62,10 @@ func on_press_key(key):
5062
if inventory_select != old_select:
5163
select_inventory()
5264

65+
if key == Controls.ACCEPT:
66+
equip_soul()
67+
slot_mode()
68+
5369
if key == Controls.CANCEL:
5470
slot_mode()
5571

@@ -69,21 +85,18 @@ func select():
6985
select_rect.rect_size = selected.rect_size
7086
select_rect.rect_position = selected.get_global_rect().position - main.get_global_rect().position
7187

72-
if false and selected.soul_name:
73-
description.visible = true
74-
description.get_node("Panel2/Text").text = Res.souls[selected.soul_name].description
75-
description.get_node("Panel1/Icon").modulate = slots.get_child(select).color
76-
else:
77-
description.visible = false
88+
description.visible = true
89+
description.get_node("Panel2/Text").text = SOUL_DESCRIPTIONS[Soul.TYPE_COLOR.keys()[select]]
90+
description.get_node("Panel1/Icon").modulate = slots.get_child(select).color
7891

7992
func select_inventory():
8093
var selected = inventory.get_child(inventory_select)
8194
select_rect.rect_size = selected.rect_size
8295
select_rect.rect_position = selected.get_global_rect().position - main.get_global_rect().position
8396

84-
if selected.soul_name:
97+
if !selected.empty():
8598
description.visible = true
86-
description.get_node("Panel2/Text").text = Res.souls[selected.soul_name].description
99+
description.get_node("Panel2/Text").text = Res.souls[selected.stack.soul].description
87100
description.get_node("Panel1/Icon").modulate = slots.get_child(select).color
88101
else:
89102
description.visible = false
@@ -129,4 +142,21 @@ func update_inventory():
129142
else:
130143
inventory.get_child(i).clear_soul()
131144

132-
select_inventory()
145+
select_inventory()
146+
147+
func update_equipment(souls):
148+
for i in 8:
149+
if souls[i] > 0:
150+
slots.get_child(i).set_soul(Res.get_res(Res.souls, souls[i]).name)
151+
else:
152+
slots.get_child(i).clear_soul()
153+
154+
select()
155+
156+
func equip_soul():
157+
var selected = inventory.get_child(inventory_select)
158+
159+
if !selected.empty():
160+
Packet.new(Packet.TYPE.EQUIP_SOUL).add_u8(select).add_u8(selected.stack.origin).send()
161+
inventory_select = -1
162+
select()

Scripts/UI/SoulSlot.gd

+17-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ export var soul = ""
66
export var color = Color.red
77
export var no_select = false
88

9-
func _ready():
10-
if !Engine.editor_hint:
11-
set_process(false)
12-
139
func _process(delta):
14-
$Type.text = type
15-
$Name.text = soul
10+
if Engine.editor_hint:
11+
$Type.text = type
12+
$Name.text = soul
13+
$Icon.self_modulate = color
14+
$Icon/LeftRect.modulate = color.darkened(0.4)
15+
$Name/RightRect.modulate = color.darkened(0.8)
16+
17+
$Name.visible = !no_select
18+
1619
$Icon/LeftRect.rect_size.x = $Type.rect_size.x + 30
1720
$Name/RightRect.rect_size.x = $Name.rect_size.x + 18
18-
$Icon.self_modulate = color
19-
$Icon/LeftRect.modulate = color.darkened(0.4)
20-
$Name/RightRect.modulate = color.darkened(0.8)
2121

22-
$Name.visible = !no_select
22+
func set_soul(soul):
23+
$Name.text = soul
24+
25+
func clear_soul():
26+
$Name.text = " --- "
27+
28+
func empty():
29+
return $Name.text == " --- "

Server/Character.cs

+26-4
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,35 @@ public void EquipItem(byte slot, byte from) {
150150
inventory.RemoveAt(from);
151151
if (oldEquip > 0) inventory.Add(oldEquip);
152152

153-
syncStats();
154-
155153
owner.SendPacket(new Packet(Packet.TYPE.INVENTORY).AddU16Array(GetInventory()));
156154
owner.SendPacket(new Packet(Packet.TYPE.EQUIPMENT).AddEquipment(GetEquipment()));
157155

156+
syncStats();
158157
var stats = new List<string>();
159158
var item = Server.GetItem(equipment.AsBsonArray[slot].AsInt32);
160159
foreach (var stat in statList) if (item.ContainsKey(stat)) stats.Add(stat);
161160
GetPlayer().SendPacket(new Packet(Packet.TYPE.STATS).AddStats(GetPlayer(), stats.ToArray()));
162161
}
163162

163+
public void EquipSoul(byte slot, byte from) {
164+
var equipment = data.GetValue("soul_equipment").AsBsonArray;
165+
var inventory = data.GetValue("souls").AsBsonArray;
166+
167+
var oldEquip = equipment[slot];
168+
equipment.AsBsonArray[slot] = inventory[from];
169+
inventory.RemoveAt(from);
170+
if (oldEquip > 0) inventory.Add(oldEquip);
171+
172+
owner.SendPacket(new Packet(Packet.TYPE.SOULS).AddU16Array(owner.GetCharacter().GetSouls()));
173+
owner.SendPacket(new Packet(Packet.TYPE.SOUL_EQUIPMENT).AddEquipment(owner.GetCharacter().GetSoulEquipment()));
174+
175+
// syncStats();
176+
// var stats = new List<string>();
177+
// var item = Server.GetItem(equipment.AsBsonArray[slot].AsInt32);
178+
// foreach (var stat in statList) if (item.ContainsKey(stat)) stats.Add(stat);
179+
// GetPlayer().SendPacket(new Packet(Packet.TYPE.STATS).AddStats(GetPlayer(), stats.ToArray()));
180+
}
181+
164182
public void Save() {
165183
database.SaveCharacter(data);
166184
}
@@ -169,12 +187,16 @@ public ushort[] GetInventory() {
169187
return getArray("inventory");
170188
}
171189

190+
public ushort[] GetEquipment() {
191+
return getArray("equipment");
192+
}
193+
172194
public ushort[] GetSouls() {
173195
return getArray("souls");
174196
}
175197

176-
public ushort[] GetEquipment() {
177-
return getArray("equipment");
198+
public ushort[] GetSoulEquipment() {
199+
return getArray("soul_equipment");
178200
}
179201

180202
private ushort[] getArray(string value) {

Server/Packet.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public enum TYPE {
1919
INVENTORY,
2020
EQUIPMENT,
2121
SOULS,
22+
SOUL_EQUIPMENT,
2223
EQUIP,
24+
EQUIP_SOUL,
2325
ITEM_GET,
2426
SOUL_GET
2527
}
@@ -143,7 +145,7 @@ public Packet AddEquipment(ushort[] equipment) {
143145

144146
List<ushort> eq = new List<ushort>();
145147

146-
for (int i = 0; i < 8; i++) {
148+
for (int i = 0; i < equipment.Length; i++) {
147149
if (equipment[i] > 0) {
148150
isEq[i] = true;
149151
eq.Add(equipment[i]);

Server/Unpacker.cs

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void HandlePacket(Database database, Player player) {
5656
player.SendPacket(new Packet(Packet.TYPE.INVENTORY).AddU16Array(player.GetCharacter().GetInventory()));
5757
player.SendPacket(new Packet(Packet.TYPE.EQUIPMENT).AddEquipment(player.GetCharacter().GetEquipment()));
5858
player.SendPacket(new Packet(Packet.TYPE.SOULS).AddU16Array(player.GetCharacter().GetSouls()));
59+
player.SendPacket(new Packet(Packet.TYPE.SOUL_EQUIPMENT).AddEquipment(player.GetCharacter().GetSoulEquipment()));
5960

6061
room.AddPlayer(player.GetCharacter());
6162
} else {
@@ -100,6 +101,10 @@ public void HandlePacket(Database database, Player player) {
100101
case Packet.TYPE.EQUIP:
101102
player.GetCharacter().EquipItem(GetU8(), GetU8());
102103

104+
break;
105+
case Packet.TYPE.EQUIP_SOUL:
106+
player.GetCharacter().EquipSoul(GetU8(), GetU8());
107+
103108
break;
104109
}
105110
}

0 commit comments

Comments
 (0)