mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:45:33 +00:00
Refactored weapon equipment system
This commit is contained in:
parent
2f76d4742e
commit
1a403d163a
10 changed files with 164 additions and 73 deletions
|
|
@ -19,6 +19,7 @@ script = ExtResource("1_qd764")
|
|||
Name = &""
|
||||
BulletData = ExtResource("2_gpot4")
|
||||
Priority = 0
|
||||
AmmoPerShot = 1
|
||||
RateOfFire = 1.0
|
||||
BulletCapacity = 10
|
||||
ReloadTime = 1.0
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
[gd_resource type="Resource" script_class="ItemsDatabase" load_steps=25 format=3 uid="uid://cdi84udi6gldt"]
|
||||
[gd_resource type="Resource" script_class="ItemsDatabase" load_steps=35 format=3 uid="uid://cdi84udi6gldt"]
|
||||
|
||||
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="1_1s15f"]
|
||||
[ext_resource type="Script" uid="uid://c23prvgfitlpd" path="res://Scripts/Resources/ItemsDatabase.cs" id="1_al8ea"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="1_nodmt"]
|
||||
[ext_resource type="Resource" uid="uid://cj5aa7btaw6q0" path="res://Resources/Items/Blue_Keycard.tres" id="2_nsx5p"]
|
||||
[ext_resource type="Resource" uid="uid://cfq121rs3bsu8" path="res://Resources/Items/Cheat_Gun_Item.tres" id="3_oark3"]
|
||||
[ext_resource type="Resource" uid="uid://cspcgkr0tane2" path="res://Resources/Items/Green_Keycard.tres" id="4_yj5fs"]
|
||||
|
|
@ -24,8 +25,17 @@
|
|||
[ext_resource type="Resource" uid="uid://diqm2ju0xakkt" path="res://Resources/Items/Yin_Yang_Ammo.tres" id="21_detwd"]
|
||||
[ext_resource type="Resource" uid="uid://ccmuffmnevrt4" path="res://Resources/Items/Yin_Yang_Gun_Pickup.tres" id="22_w8yo3"]
|
||||
[ext_resource type="Resource" uid="uid://b0qheywm2wej3" path="res://Resources/Items/Yin_Yang_Orb.tres" id="23_nq6hj"]
|
||||
[ext_resource type="Resource" uid="uid://ckfqrq8a0uj1t" path="res://Resources/Items/LaserWeapon.tres" id="25_5stko"]
|
||||
[ext_resource type="Resource" uid="uid://c57od7cpn5kwf" path="res://Resources/Items/IceShotgun_Sawed_T2.tres" id="26_5x77y"]
|
||||
[ext_resource type="Resource" uid="uid://btk4kojtepwv" path="res://Resources/Items/IceShotgun_Sawed_T1.tres" id="27_p1hpt"]
|
||||
[ext_resource type="Resource" uid="uid://dv0cdlx8d6evm" path="res://Resources/Items/IceShotgun_Sawed_T0.tres" id="28_b6dqw"]
|
||||
[ext_resource type="Resource" uid="uid://c01jixi7b2s7v" path="res://Resources/Items/IceShotgun_T1.tres" id="29_a5xwj"]
|
||||
[ext_resource type="Resource" uid="uid://bhllj7r3oxipf" path="res://Resources/Items/IceShotgun_T2.tres" id="30_44qof"]
|
||||
[ext_resource type="Resource" uid="uid://oa8s6xydriib" path="res://Resources/Items/Generic_Keycard.tres" id="31_i5d5q"]
|
||||
[ext_resource type="Resource" uid="uid://cajqlnyvlmybe" path="res://Resources/Items/IcicleRepeater_Improved.tres" id="32_42kyh"]
|
||||
[ext_resource type="Resource" uid="uid://dwwbyyy3fo4bt" path="res://Resources/Items/IcicleRepeater_Advanced.tres" id="33_q4lxx"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_al8ea")
|
||||
LootItems = [ExtResource("1_1s15f"), ExtResource("2_nsx5p"), ExtResource("3_oark3"), ExtResource("4_yj5fs"), ExtResource("5_wigtd"), ExtResource("6_ador3"), ExtResource("7_xxd6q"), ExtResource("8_33up1"), ExtResource("9_a23i7"), ExtResource("10_0hw56"), ExtResource("11_nodmt"), ExtResource("12_5stko"), ExtResource("13_5x77y"), ExtResource("14_p1hpt"), ExtResource("15_b6dqw"), ExtResource("16_a5xwj"), ExtResource("17_44qof"), ExtResource("18_i5d5q"), ExtResource("19_42kyh"), ExtResource("20_q4lxx"), ExtResource("21_detwd"), ExtResource("22_w8yo3"), ExtResource("23_nq6hj")]
|
||||
LootItems = Array[ExtResource("1_nodmt")]([ExtResource("1_1s15f"), ExtResource("2_nsx5p"), ExtResource("3_oark3"), ExtResource("4_yj5fs"), ExtResource("5_wigtd"), ExtResource("6_ador3"), ExtResource("7_xxd6q"), ExtResource("8_33up1"), ExtResource("9_a23i7"), ExtResource("10_0hw56"), ExtResource("11_nodmt"), ExtResource("12_5stko"), ExtResource("13_5x77y"), ExtResource("14_p1hpt"), ExtResource("15_b6dqw"), ExtResource("16_a5xwj"), ExtResource("17_44qof"), ExtResource("18_i5d5q"), ExtResource("19_42kyh"), ExtResource("20_q4lxx"), ExtResource("21_detwd"), ExtResource("22_w8yo3"), ExtResource("23_nq6hj"), ExtResource("25_5stko"), ExtResource("26_5x77y"), ExtResource("27_p1hpt"), ExtResource("28_b6dqw"), ExtResource("29_a5xwj"), ExtResource("30_44qof"), ExtResource("31_i5d5q"), ExtResource("32_42kyh"), ExtResource("33_q4lxx")])
|
||||
metadata/_custom_type_script = "uid://c23prvgfitlpd"
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ script = ExtResource("4_17dut")
|
|||
Name = &""
|
||||
BulletData = SubResource("Resource_5eesc")
|
||||
Priority = 0
|
||||
AmmoPerShot = 1
|
||||
RateOfFire = 0.4
|
||||
BulletCapacity = 20
|
||||
ReloadTime = 2.0
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@
|
|||
[ext_resource type="PackedScene" uid="uid://cl4r3t4c1klv7" path="res://Scenes/Interactable/Switch_Box.tscn" id="38_qnbhd"]
|
||||
[ext_resource type="Script" uid="uid://d0a0o50j82eo6" path="res://Scripts/Activables/ScriptableBase.cs" id="42_wigyb"]
|
||||
[ext_resource type="PackedScene" uid="uid://fxvlaidieiv7" path="res://Scenes/Interactable/ScriptableAreaTrigger.tscn" id="43_kf3qc"]
|
||||
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="44_j86ly"]
|
||||
[ext_resource type="Script" uid="uid://dkihoo85jfec5" path="res://Scripts/Resources/Events/MovePlayerEvent.cs" id="44_klwgh"]
|
||||
[ext_resource type="PackedScene" uid="uid://dx1urm7nttkqk" path="res://Scenes/Actors/level_teleporter.tscn" id="44_q5xi2"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0k2grrc8xp1l" path="res://Scenes/Props/BigTank.tscn" id="45_5qg27"]
|
||||
|
|
@ -84,6 +83,7 @@
|
|||
[ext_resource type="Resource" uid="uid://c57od7cpn5kwf" path="res://Resources/Items/IceShotgun_Sawed_T2.tres" id="58_dfo5i"]
|
||||
[ext_resource type="PackedScene" uid="uid://bjskkeb3ppcs8" path="res://Scenes/Actors/Turret360.tscn" id="62_h0jm4"]
|
||||
[ext_resource type="Script" uid="uid://v57xjmhi28kw" path="res://Scripts/Resources/Events/ControlActorEvent.cs" id="64_rphi8"]
|
||||
[ext_resource type="Script" uid="uid://b5fesrd4lv8t1" path="res://Scripts/Resources/Events/EventResource.cs" id="66_ldb17"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0gpbkxdfbnjh" path="res://Scenes/Actors/ForceField_Horizontal.tscn" id="66_nxn3h"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjsnhyl0nqbau" path="res://Scenes/Props/ICCTv.tscn" id="71_ji7au"]
|
||||
[ext_resource type="Resource" uid="uid://cfdvg162u65sr" path="res://Resources/Enemies/Thermathron.tres" id="71_xhinl"]
|
||||
|
|
@ -167,7 +167,7 @@ DamageType = 0
|
|||
OverrideControllable = false
|
||||
Controllable = false
|
||||
OverrideCreationModifier = false
|
||||
TimeModifiers = Array[ExtResource("44_j86ly")]([])
|
||||
TimeModifiers = []
|
||||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ ActivationType = 0
|
|||
Targets = Array[NodePath]([NodePath("../Rumia")])
|
||||
WaitForCompletion = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_uh0gg"]
|
||||
[sub_resource type="Resource" id="Resource_7lma1"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("49_0si7g")
|
||||
Target = NodePath(".")
|
||||
|
|
@ -330,7 +330,7 @@ DamageType = 0
|
|||
OverrideControllable = false
|
||||
Controllable = false
|
||||
OverrideCreationModifier = false
|
||||
TimeModifiers = Array[ExtResource("44_j86ly")]([])
|
||||
TimeModifiers = []
|
||||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
|
|
@ -907,7 +907,7 @@ Invisible = true
|
|||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="ScriptableAreaTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps/DebugTeleporter" instance=ExtResource("43_kf3qc")]
|
||||
Events = [SubResource("Resource_usuub")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_usuub")])
|
||||
|
||||
[node name="BlueKeycard2" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("35_rblsn")]
|
||||
position = Vector2(-1032, -317)
|
||||
|
|
@ -1103,7 +1103,7 @@ position = Vector2(-1423, -188)
|
|||
[node name="LevelStartTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-762, -129)
|
||||
scale = Vector2(1.455, 1.455)
|
||||
Events = [SubResource("Resource_5er5x"), SubResource("Resource_b25hy")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_5er5x"), SubResource("Resource_b25hy")])
|
||||
|
||||
[node name="AreaTrigger2" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("28_6au4t")]
|
||||
position = Vector2(-435, -162)
|
||||
|
|
@ -1146,7 +1146,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer2"]
|
||||
position = Vector2(120, 25)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_wma5c")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_wma5c")])
|
||||
|
||||
[node name="Computer8" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-2073, -215)
|
||||
|
|
@ -1157,7 +1157,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer8"]
|
||||
position = Vector2(120, 25)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_dferh")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_dferh")])
|
||||
|
||||
[node name="Computer6" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1113, -139)
|
||||
|
|
@ -1167,7 +1167,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer6"]
|
||||
position = Vector2(0, 1)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_cxj4w")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_cxj4w")])
|
||||
|
||||
[node name="Computer7" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1175.36, 213.708)
|
||||
|
|
@ -1178,7 +1178,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Computer7Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer7"]
|
||||
position = Vector2(0, 1)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_tcc7d")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_tcc7d")])
|
||||
|
||||
[node name="Computer5" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1344, -251)
|
||||
|
|
@ -1186,7 +1186,7 @@ Targets = [NodePath("Computer5Script")]
|
|||
|
||||
[node name="Computer5Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer5"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_fasrq"), SubResource("Resource_mah4x"), SubResource("Resource_0bqta")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_fasrq"), SubResource("Resource_mah4x"), SubResource("Resource_0bqta")])
|
||||
|
||||
[node name="Computer3" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-612.57, -358.528)
|
||||
|
|
@ -1194,7 +1194,7 @@ Target = NodePath("Script")
|
|||
|
||||
[node name="Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer3"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_o2kpk")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_o2kpk")])
|
||||
|
||||
[node name="Computer4" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-791, -505)
|
||||
|
|
@ -1202,7 +1202,7 @@ Target = NodePath("Node2D")
|
|||
|
||||
[node name="Node2D" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_s3g2w")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_s3g2w")])
|
||||
|
||||
[node name="Label" type="Label" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
|
||||
offset_left = -5.0
|
||||
|
|
@ -1219,11 +1219,11 @@ EnemyData = ExtResource("71_xhinl")
|
|||
[node name="BossBattleEndScript" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps"]
|
||||
position = Vector2(-1628.53, -477.628)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_068l7"), SubResource("Resource_l3nop")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_068l7"), SubResource("Resource_l3nop")])
|
||||
|
||||
[node name="BossBattleStartScript" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-1487, -396)
|
||||
Events = [SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_uh0gg")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_7lma1")])
|
||||
|
||||
[node name="Enemy13" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
|
||||
position = Vector2(-1657, -788)
|
||||
|
|
@ -1540,7 +1540,7 @@ position = Vector2(-2232, -203)
|
|||
|
||||
[node name="ScriptableAreaTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-2063, -232)
|
||||
Events = [SubResource("Resource_l476f"), SubResource("Resource_dskij")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_l476f"), SubResource("Resource_dskij")])
|
||||
|
||||
[node name="ShieldExtendPickup" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("103_0bqta")]
|
||||
position = Vector2(-1646, 38)
|
||||
|
|
@ -1668,7 +1668,7 @@ position = Vector2(-1633, 391)
|
|||
|
||||
[node name="MovementSensorLonger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("112_j86ly")]
|
||||
position = Vector2(-1495, 516)
|
||||
Events = [SubResource("Resource_uslvo")]
|
||||
Events = Array[ExtResource("66_ldb17")]([SubResource("Resource_uslvo")])
|
||||
|
||||
[node name="WallEmitter" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("113_dferh")]
|
||||
position = Vector2(-1480, 451)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -10,7 +11,28 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
{
|
||||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = [];
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
private int _currentWeaponIndex = 0;
|
||||
|
||||
private int CurrentWeaponIndex
|
||||
{
|
||||
get => Math.Clamp(_currentWeaponIndex, 0, EquippedWeapons.Count -1);
|
||||
|
||||
set
|
||||
{
|
||||
if (value > EquippedWeapons.Count)
|
||||
{
|
||||
_currentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
_currentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
_currentWeaponIndex = value;
|
||||
}
|
||||
}
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
|
|
@ -18,78 +40,73 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
private CharacterBody2D _parent;
|
||||
|
||||
//public Vector2 FacingDirection
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Init(CharacterBody2D parent)
|
||||
{
|
||||
_parent = parent;
|
||||
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_inventoryManager.WeaponEquip += this.EquipWeapon;
|
||||
_inventoryManager.WeaponEquip += this.OnInventoryWeaponEquipped;
|
||||
|
||||
_inventoryManager.ItemAdded += (LootItem item, int amount) =>
|
||||
{
|
||||
if (item.Item == ItemTypes.Weapon)
|
||||
{
|
||||
SpawnPlayerWeapon(item);
|
||||
}
|
||||
};
|
||||
_inventoryManager.ItemAdded += OnInventoryWeaponAdded;
|
||||
}
|
||||
|
||||
private void OnInventoryWeaponEquipped(string itemKey)
|
||||
{
|
||||
Equip(itemKey, true);
|
||||
}
|
||||
|
||||
private void OnInventoryWeaponAdded(LootItem item, int amount)
|
||||
{
|
||||
if (item.Item is not ItemTypes.Weapon) return;
|
||||
Equip(item, false);
|
||||
}
|
||||
|
||||
private void EquipStartupWeapon()
|
||||
{
|
||||
if (EquippedWeapon is not null) return;
|
||||
if (!string.IsNullOrWhiteSpace(GlobalState.Session.EquippedWeaponId))
|
||||
{
|
||||
// equip it
|
||||
Equip(GlobalState.Session.EquippedWeaponId, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to equip whatever is first
|
||||
var weaponData = InventoryManager.Instance.Items.FirstOrDefault(x => x.Item.Item is ItemTypes.Weapon);
|
||||
if (weaponData is null) return;
|
||||
|
||||
Equip(weaponData.Item.ItemKey, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// This is a soft equip
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
}
|
||||
|
||||
public void EquipWeapon(string itemKey)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemKey)) return;
|
||||
var weapon = EquippedWeapons.FirstOrDefault(x => x.WeaponData.ItemKey == itemKey);
|
||||
|
||||
if (weapon is null)
|
||||
{
|
||||
// Spawn a weapon
|
||||
InventoryManager.Instance.TryGetItem(itemKey, out var item);
|
||||
SpawnPlayerWeapon(item.Item);
|
||||
return;
|
||||
};
|
||||
|
||||
EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
private void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
GlobalState.Session.EquippedWeaponId = weapon.WeaponData.ItemKey;
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
{
|
||||
CurrentWeaponIndex += 1;
|
||||
if (CurrentWeaponIndex > EquippedWeapons.Count - 1)
|
||||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
Equip(EquippedWeapons[CurrentWeaponIndex], true);
|
||||
}
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
if (CurrentWeaponIndex < 0)
|
||||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
Equip(EquippedWeapons[CurrentWeaponIndex], true);
|
||||
}
|
||||
|
||||
public void Shoot(Vector2 direction)
|
||||
|
|
@ -100,23 +117,83 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
||||
private void SpawnPlayerWeapon(LootItem startingItem)
|
||||
// Remastered method
|
||||
private LootItem GetItemFromInventory(string itemKey)
|
||||
{
|
||||
return InventoryManager.Instance.Items.FirstOrDefault(x => x.Item.ItemKey == itemKey)?.Item;
|
||||
}
|
||||
|
||||
private Weapon GetWeaponFromLocal(string itemKey)
|
||||
{
|
||||
return EquippedWeapons.FirstOrDefault(x => x.WeaponData.ItemKey == itemKey);
|
||||
}
|
||||
|
||||
// Remastered method
|
||||
private Weapon SpawnWeapon(string itemKey)
|
||||
{
|
||||
return SpawnWeapon(GetItemFromInventory(itemKey));
|
||||
}
|
||||
|
||||
// Remastered method
|
||||
private Weapon SpawnWeapon(LootItem startingItem)
|
||||
{
|
||||
if (WeaponTemplate == null)
|
||||
{
|
||||
GD.Print("Could not spawn weapon because template is null");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Check if it's not spawned already
|
||||
var maybeExistingWeapon = GetWeaponFromLocal(startingItem.ItemKey);
|
||||
if (maybeExistingWeapon is not null) return maybeExistingWeapon;
|
||||
|
||||
var weapon = this.CreateSibling<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
|
||||
this.AddWeapon(weapon);
|
||||
|
||||
if (this.EquippedWeapon == null)
|
||||
{
|
||||
this.EquipWeapon(weapon);
|
||||
}
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public Weapon Equip(LootItem item, bool force)
|
||||
{
|
||||
var maybeExistingWeapon = GetWeaponFromLocal(item.ItemKey);
|
||||
if (maybeExistingWeapon is not null) return Equip(maybeExistingWeapon, force);
|
||||
|
||||
// Spawn if not present
|
||||
var spawnedWeapon = SpawnWeapon(item);
|
||||
return Equip(spawnedWeapon, force);
|
||||
}
|
||||
|
||||
public Weapon Equip(string itemKey, bool force)
|
||||
{
|
||||
// Check in local inventory first
|
||||
var maybeExistingWeapon = GetWeaponFromLocal(itemKey);
|
||||
if (maybeExistingWeapon is not null) return Equip(maybeExistingWeapon, force);
|
||||
|
||||
// Spawn if not present
|
||||
var spawnedWeapon = SpawnWeapon(itemKey);
|
||||
return Equip(spawnedWeapon, force);
|
||||
}
|
||||
|
||||
public Weapon Equip(Weapon weapon, bool force)
|
||||
{
|
||||
// When we get here we already have a spawned weapon and it's in the list
|
||||
|
||||
// Always equip it if there's nothing equipped
|
||||
if (this.EquippedWeapon is null)
|
||||
{
|
||||
this.EquipWeapon(weapon);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
// If it's a soft equip check for priority
|
||||
if (!force && this.EquippedWeapon.WeaponData.Priority < weapon.WeaponData.Priority)
|
||||
{
|
||||
this.EquipWeapon(weapon);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
EquipWeapon(weapon);
|
||||
return weapon;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,8 +170,6 @@ public partial class GameManager : Node2D
|
|||
{
|
||||
Unpause();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DelayPlayerSpawn()
|
||||
|
|
|
|||
|
|
@ -211,12 +211,12 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
_weaponProvider.AddWeapon(weapon);
|
||||
_weaponProvider.Equip(weapon, false);
|
||||
}
|
||||
|
||||
public void EquipWeapon(string itemKey)
|
||||
{
|
||||
_weaponProvider.EquipWeapon(itemKey);
|
||||
_weaponProvider.Equip(itemKey, true);
|
||||
}
|
||||
|
||||
public void UseItem(LootItem item, int currentAmount)
|
||||
|
|
@ -258,7 +258,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
_weaponProvider.EquipWeapon(weapon);
|
||||
_weaponProvider.Equip(weapon, true);
|
||||
}
|
||||
|
||||
private void FindInteractable()
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public partial class ItemsMenu : ItemList
|
|||
public void Fill()
|
||||
{
|
||||
var sortedItems = InventoryManager.Instance.Items.OrderBy(x => x.Item.ItemKey.ToString()).ToList();
|
||||
// If it crashes here I might have forgot to add new items to the itemsdatabase
|
||||
foreach (var item in sortedItems)
|
||||
{
|
||||
if (item.Count <= 0) continue;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Utils;
|
||||
|
||||
|
|
@ -19,6 +20,8 @@ public class SessionSettings
|
|||
|
||||
public float Health { get; set; }
|
||||
public float Shield { get; set; }
|
||||
|
||||
public string EquippedWeaponId { get; set; }
|
||||
|
||||
public float DifficultyDamageMultiplier => this.Difficulty switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@
|
|||
},
|
||||
"res://Resources/Weapons/Enemy/": {
|
||||
"metadata/_custom_type_script": {
|
||||
"visibility": 0
|
||||
"visibility": 0.0
|
||||
},
|
||||
"resource_local_to_scene": {
|
||||
"visibility": 0
|
||||
"visibility": 0.0
|
||||
},
|
||||
"resource_name": {
|
||||
"visibility": 0
|
||||
"visibility": 0.0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue