Fixed an issue where items were overwritten using the wrong index when picking them up.
修复捡起物品时,使用错误的索引导致物品覆盖的问题。
This commit is contained in:
parent
291ef653f0
commit
feeb8261e3
|
@ -33,13 +33,10 @@ radius = 172.29
|
|||
collision_layer = 64
|
||||
collision_mask = 38
|
||||
script = ExtResource("1_ubaid")
|
||||
InitWeaponRes = null
|
||||
CharacterName = "character_evil_crow"
|
||||
CanMutateAfterDeath = false
|
||||
_initialHp = null
|
||||
MaxHp = 50
|
||||
CampId = "Mazoku"
|
||||
LootListId = null
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(2, 10)
|
||||
|
|
|
@ -29,12 +29,8 @@ collision_mask = 162
|
|||
platform_floor_layers = 4294967042
|
||||
platform_wall_layers = 128
|
||||
script = ExtResource("1_1dlls")
|
||||
CharacterName = null
|
||||
CanMutateAfterDeath = null
|
||||
_initialHp = null
|
||||
MaxHp = 32
|
||||
CampId = "Default"
|
||||
LootListId = null
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CapsuleShape2D_bb8wt")
|
||||
|
|
|
@ -34,10 +34,8 @@ radius = 172.29
|
|||
collision_layer = 64
|
||||
collision_mask = 38
|
||||
script = ExtResource("1_ubaid")
|
||||
InitWeaponRes = null
|
||||
CharacterName = "character_necromancer"
|
||||
CanMutateAfterDeath = false
|
||||
_initialHp = null
|
||||
MaxHp = 50
|
||||
CampId = "Mazoku"
|
||||
LootListId = "test"
|
||||
|
|
|
@ -92,8 +92,6 @@ collision_layer = 256
|
|||
collision_mask = 160
|
||||
script = ExtResource("1_t1qdg")
|
||||
Path = "res://prefab/ui/SpellEditorUI.tscn"
|
||||
_initialDurability = null
|
||||
_maxDurability = null
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-0.5, -0.5)
|
||||
|
|
|
@ -13,7 +13,6 @@ radius = 52.6118
|
|||
collision_layer = 256
|
||||
collision_mask = 160
|
||||
script = ExtResource("1_hfnuj")
|
||||
_initialDurability = null
|
||||
_maxDurability = 1
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
|
|
@ -18,9 +18,6 @@ collision_mask = 34
|
|||
angular_damp = -1.0
|
||||
script = ExtResource("1_nydte")
|
||||
FiringIntervalAsMillisecond = 1000
|
||||
_recoilStrength = null
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -16,9 +16,6 @@ collision_mask = 34
|
|||
angular_damp = -1.0
|
||||
script = ExtResource("1_gg5rs")
|
||||
_packedScenePath = "res://prefab/entitys/BlackenedAboriginalWarrior.tscn"
|
||||
_projectilePath = null
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -15,12 +15,6 @@ collision_layer = 8
|
|||
collision_mask = 34
|
||||
angular_damp = -1.0
|
||||
script = ExtResource("1_cnhod")
|
||||
NumberOfProjectiles = null
|
||||
RandomAngle = null
|
||||
UnitRadian = null
|
||||
_projectilePath = null
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -14,8 +14,6 @@ collision_layer = 8
|
|||
collision_mask = 38
|
||||
script = ExtResource("1_slakl")
|
||||
NumberSlots = 30
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -23,7 +23,7 @@ polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Arr
|
|||
outlines = Array[PackedVector2Array]([PackedVector2Array(479, 34, 228, 32, 226, 1, 159, 1, 160, 31, 32, 35, 33, 97, 1, 97, -1, 162, 512, 160, 509, 96, 480, 97)])
|
||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||
|
||||
[node name="InitialRoom" type="Node2D"]
|
||||
[node name="InitialRoom2" type="Node2D"]
|
||||
|
||||
[node name="RoomArea" type="Area2D" parent="."]
|
||||
collision_mask = 0
|
||||
|
@ -89,5 +89,3 @@ texture = ExtResource("3_r2p3x")
|
|||
|
||||
[node name="RigidBody2D" parent="." instance=ExtResource("4_rean8")]
|
||||
position = Vector2(239, 101)
|
||||
_initialDurability = null
|
||||
_maxDurability = null
|
||||
|
|
|
@ -55,7 +55,6 @@ shape = SubResource("RectangleShape2D_131jn")
|
|||
[node name="Marker2D" type="Marker2D" parent="."]
|
||||
position = Vector2(237, 69)
|
||||
script = ExtResource("2_7q101")
|
||||
ResPath = null
|
||||
metadata/ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn"
|
||||
|
||||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
|
||||
|
|
|
@ -20,7 +20,7 @@ polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Arr
|
|||
outlines = Array[PackedVector2Array]([PackedVector2Array(36, 32, 731, 32, 733, 258, 766, 257, 767, 316, 35, 317)])
|
||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||
|
||||
[node name="InitialRoom" type="Node2D"]
|
||||
[node name="InitialRoom3" type="Node2D"]
|
||||
|
||||
[node name="RoomArea" type="Area2D" parent="."]
|
||||
|
||||
|
@ -103,8 +103,6 @@ texture = ExtResource("6_dbg76")
|
|||
|
||||
[node name="RigidBody2D" parent="." instance=ExtResource("5_0kep0")]
|
||||
position = Vector2(227, 283)
|
||||
_initialDurability = null
|
||||
_maxDurability = null
|
||||
|
||||
[node name="WoodenBox" parent="." instance=ExtResource("7_jybe6")]
|
||||
position = Vector2(715, 244)
|
||||
|
|
|
@ -125,8 +125,6 @@ position = Vector2(711, 98)
|
|||
|
||||
[node name="RigidBody2D" parent="." instance=ExtResource("5_ll4ng")]
|
||||
position = Vector2(473, 285)
|
||||
_initialDurability = null
|
||||
_maxDurability = null
|
||||
|
||||
[node name="TripleShotSpell" type="Sprite2D" parent="."]
|
||||
position = Vector2(637, 85)
|
||||
|
|
|
@ -18,12 +18,6 @@ collision_layer = 8
|
|||
collision_mask = 34
|
||||
angular_damp = -1.0
|
||||
script = ExtResource("1_snmy1")
|
||||
_maxDamage = null
|
||||
_minDamage = null
|
||||
FiringIntervalAsMillisecond = null
|
||||
_recoilStrength = null
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -21,8 +21,6 @@ _fireSequentially = true
|
|||
FiringIntervalAsMillisecond = 300
|
||||
_recoilStrength = 5
|
||||
UniqueIcon = ExtResource("3_31iau")
|
||||
_minContactInjury = null
|
||||
_maxContactInjury = null
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -23,16 +23,6 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
//_selectIndex默认为0.
|
||||
private int _selectIndex;
|
||||
|
||||
/// <summary>
|
||||
/// <para>The next available index</para>
|
||||
/// <para>下个可用的索引</para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///<para>For example, the variable [1,2,3,5,6] represents 4, or the variable [1,2,3,4,5,6,7] represents 8.</para>
|
||||
///<para>例如[1,2,3,5,6]这个变量表示4,再或者[1,2,3,4,5,6,7]这个变量表示8。</para>
|
||||
/// </remarks>
|
||||
private int _nextAvailableIndex;
|
||||
|
||||
/// <summary>
|
||||
/// <para>The type of item that can be added to the item container</para>
|
||||
/// <para>物品容器允许添加的物品类型</para>
|
||||
|
@ -132,34 +122,41 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
/// <para>Update the next available index location</para>
|
||||
/// <para>更新下个可用的索引位置</para>
|
||||
/// </summary>
|
||||
private void UpdateNextAvailableIndex()
|
||||
/// <remarks>
|
||||
///<para>For example, the variable [1,2,3,5,6] represents 4, or the variable [1,2,3,4,5,6,7] represents 8.</para>
|
||||
///<para>例如[1,2,3,5,6]这个变量表示4,再或者[1,2,3,4,5,6,7]这个变量表示8。</para>
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
///<para>The next available index is returned after obtaining failure<see cref="UnknownIndex"/></para>
|
||||
///<para>下次可用的索引,获取失败返回<see cref="UnknownIndex"/></para>
|
||||
/// </returns>
|
||||
private int GetNextAvailableIndex()
|
||||
{
|
||||
_nextAvailableIndex = UnknownIndex;
|
||||
if (totalCapacity <= 0)
|
||||
{
|
||||
return;
|
||||
return UnknownIndex;
|
||||
}
|
||||
for (var i = 0; i < totalCapacity; i++)
|
||||
{
|
||||
var contains = _itemDictionary.ContainsKey(i);
|
||||
if (!contains)
|
||||
{
|
||||
_nextAvailableIndex = i;
|
||||
return;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return UnknownIndex;
|
||||
}
|
||||
|
||||
public int AddItem(IItem item)
|
||||
{
|
||||
var nextAvailableIndex = GetNextAvailableIndex();
|
||||
if (item.MaxQuantity == 1)
|
||||
{
|
||||
if (_nextAvailableIndex == UnknownIndex)
|
||||
if (nextAvailableIndex == UnknownIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var nextAvailableIndex = _nextAvailableIndex;
|
||||
_itemDictionary[nextAvailableIndex] = item;
|
||||
item.Index = nextAvailableIndex;
|
||||
item.ItemContainer = this;
|
||||
|
@ -167,7 +164,6 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
{
|
||||
item.HideSelf();
|
||||
}
|
||||
UpdateNextAvailableIndex();
|
||||
UpdateSelectStatus(nextAvailableIndex, item);
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
{
|
||||
|
@ -221,24 +217,22 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
|
||||
//Add the rest to the container.
|
||||
//添加剩余到容器内。
|
||||
if (_nextAvailableIndex == UnknownIndex)
|
||||
if (nextAvailableIndex == UnknownIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var finalNextAvailableIndex = _nextAvailableIndex;
|
||||
_itemDictionary[finalNextAvailableIndex] = item;
|
||||
item.Index = finalNextAvailableIndex;
|
||||
_itemDictionary[nextAvailableIndex] = item;
|
||||
item.Index = nextAvailableIndex;
|
||||
item.ItemContainer = this;
|
||||
if (finalNextAvailableIndex != _selectIndex)
|
||||
if (nextAvailableIndex != _selectIndex)
|
||||
{
|
||||
item.HideSelf();
|
||||
}
|
||||
UpdateNextAvailableIndex();
|
||||
UpdateSelectStatus(finalNextAvailableIndex, item);
|
||||
UpdateSelectStatus(nextAvailableIndex, item);
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
{
|
||||
NewItem = item,
|
||||
NewIndex = finalNextAvailableIndex,
|
||||
NewIndex = nextAvailableIndex,
|
||||
Type = Config.ItemDataChangeEventType.Add
|
||||
});
|
||||
return originalQuantity;
|
||||
|
@ -355,7 +349,6 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
//输入的数量小于0,则移除全部物品。
|
||||
item.Quantity = 0;
|
||||
_itemDictionary.Remove(itemIndex);
|
||||
UpdateNextAvailableIndex();
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
{
|
||||
NewItem = item,
|
||||
|
@ -370,7 +363,6 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
if (item.Quantity < 1)
|
||||
{
|
||||
_itemDictionary.Remove(itemIndex);
|
||||
UpdateNextAvailableIndex();
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
{
|
||||
NewItem = item,
|
||||
|
|
Loading…
Reference in New Issue
Block a user