diff --git a/scripts/Config.cs b/scripts/Config.cs index 98e4d42..fa14572 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -20,7 +20,7 @@ public static class Config /// public const string Patrol = "Patrol"; } - + /// /// Loot table ID /// 战利品表ID @@ -90,7 +90,7 @@ public static class Config /// 抛出的物品击中敌人后减少的速度百分比 /// public const float ThrownItemsHitEnemiesReduceSpeedByPercentage = 0.5f; - + /// /// How much blood does a heart represent /// 一颗心代表多少血量 diff --git a/scripts/behaviorTree/BehaviorNode.cs b/scripts/behaviorTree/BehaviorNode.cs index f2f8c58..202e05b 100644 --- a/scripts/behaviorTree/BehaviorNode.cs +++ b/scripts/behaviorTree/BehaviorNode.cs @@ -25,6 +25,7 @@ public partial class BehaviorNode : Node2D { return; } + Root.Execute(isPhysicsProcess, delta); } } \ No newline at end of file diff --git a/scripts/behaviorTree/ai/AiPickNode.cs b/scripts/behaviorTree/ai/AiPickNode.cs index 9f98d0e..3f09278 100644 --- a/scripts/behaviorTree/ai/AiPickNode.cs +++ b/scripts/behaviorTree/ai/AiPickNode.cs @@ -1,5 +1,4 @@ using ColdMint.scripts.character; - using WeaponTemplate = ColdMint.scripts.weapon.WeaponTemplate; namespace ColdMint.scripts.behaviorTree.ai; @@ -10,8 +9,6 @@ namespace ColdMint.scripts.behaviorTree.ai; /// public class AiPickNode : BehaviorTreeNodeTemplate { - - public AiCharacter? Character { get; set; } public override int Execute(bool isPhysicsProcess, double delta) @@ -51,7 +48,7 @@ public class AiPickNode : BehaviorTreeNodeTemplate { closestDistance = distanceLength; closestWeapon = weaponTemplate; - } + } } //绘制一条线,从AI到武器 diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs index b3b0026..7616379 100644 --- a/scripts/character/Player.cs +++ b/scripts/character/Player.cs @@ -3,6 +3,7 @@ using System.Text; using System.Threading.Tasks; using ColdMint.scripts.damage; using ColdMint.scripts.deathInfo; +using ColdMint.scripts.debug; using ColdMint.scripts.inventory; using ColdMint.scripts.map.events; using ColdMint.scripts.utils; @@ -49,6 +50,7 @@ public partial class Player : CharacterTemplate { base._Ready(); CharacterName = TranslationServerUtils.Translate("default_player_name"); + LogCat.LogWithFormat("player_spawn_debug", ReadOnlyCharacterName, GlobalPosition); _floatLabelPackedScene = GD.Load("res://prefab/ui/FloatLabel.tscn"); _parabola = GetNode("Parabola"); _platformDetectionRayCast2D = GetNode("PlatformDetectionRayCast"); diff --git a/scripts/inventory/HotBar.cs b/scripts/inventory/HotBar.cs index 16ae362..70ef617 100644 --- a/scripts/inventory/HotBar.cs +++ b/scripts/inventory/HotBar.cs @@ -1,5 +1,3 @@ -using System; -using ColdMint.scripts.map.events; using ColdMint.scripts.utils; using Godot; @@ -13,18 +11,20 @@ public partial class HotBar : HBoxContainer { private IItemContainer? _itemContainer; - Action? SelectedItemSlotChangeEvent { get; set; } public override void _Ready() { base._Ready(); _itemContainer = new UniversalItemContainer(); _itemContainer.SupportSelect = true; - _itemContainer.SelectedItemSlotChangeEvent += SelectedItemSlotChangeEvent; NodeUtils.DeleteAllChild(this); for (var i = 0; i < Config.HotBarSize; i++) { - _itemContainer.AddItemSlot(this); + var itemSlotNode = _itemContainer.AddItemSlot(this); + if (itemSlotNode != null) + { + itemSlotNode.BackpackAllowed = true; + } } } @@ -113,13 +113,4 @@ public partial class HotBar : HBoxContainer { return _itemContainer; } - - public override void _ExitTree() - { - base._ExitTree(); - if (_itemContainer != null) - { - _itemContainer.SelectedItemSlotChangeEvent -= SelectedItemSlotChangeEvent; - } - } } \ No newline at end of file diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 7f50852..7a120f1 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -85,7 +85,7 @@ public partial class ItemSlotNode : MarginContainer return false; } - return _item == null; + return CanAddItem(item); } /// @@ -125,7 +125,7 @@ public partial class ItemSlotNode : MarginContainer { return null; } - + if (number > _item.Quantity) { //The number of item instances created exceeds the current number of items @@ -163,9 +163,15 @@ public partial class ItemSlotNode : MarginContainer } itemSlotNode.Item = null; - Item = item; + AddItem(item); } + /// + /// Whether to place a backpack in the current slot + /// 当前槽位是否允许放置背包 + /// + public bool BackpackAllowed { get; set; } + public bool IsSelect { get => _isSelect; @@ -282,6 +288,12 @@ public partial class ItemSlotNode : MarginContainer public bool CanAddItem(IItem item) { + if (!BackpackAllowed && item is Packsack) + { + //如果禁止放置背包,且新物品是背包 + return false; + } + if (_item == null) { //If there is no item in the current item slot, it is allowed to add. @@ -352,6 +364,7 @@ public partial class ItemSlotNode : MarginContainer { node2D.QueueFree(); } + UpdateQuantityLabel(); return true; } diff --git a/scripts/inventory/Packsack.cs b/scripts/inventory/Packsack.cs index 0fe1e20..031127f 100644 --- a/scripts/inventory/Packsack.cs +++ b/scripts/inventory/Packsack.cs @@ -30,7 +30,7 @@ public partial class Packsack : PickAbleTemplate _packsackUi = NodeUtils.InstantiatePackedScene(_packedScene); if (_packsackUi != null) { - NodeUtils.CallDeferredReparent(this, _packsackUi); + NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(_packsackUi, this), _packsackUi); _packsackUi.Title = Name; _packsackUi.ItemContainer = ItemContainer; } diff --git a/scripts/map/AiCharacterSpawn.cs b/scripts/map/AiCharacterSpawn.cs index c8d953e..03d598a 100644 --- a/scripts/map/AiCharacterSpawn.cs +++ b/scripts/map/AiCharacterSpawn.cs @@ -48,8 +48,8 @@ public partial class AiCharacterSpawn : Marker2D return; } - NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(aiCharacter, this), aiCharacter); - aiCharacter.Position = GlobalPosition; + NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.AiCharacterContainer, aiCharacter); + aiCharacter.GlobalPosition = GlobalPosition; } public override void _ExitTree() diff --git a/scripts/map/PlayerSpawn.cs b/scripts/map/PlayerSpawn.cs index 8206fe6..a1c3df4 100644 --- a/scripts/map/PlayerSpawn.cs +++ b/scripts/map/PlayerSpawn.cs @@ -28,7 +28,7 @@ public partial class PlayerSpawn : Marker2D if (GameSceneNodeHolder.Player != null) { GameSceneNodeHolder.Player.ProcessMode = ProcessModeEnum.Inherit; - GameSceneNodeHolder.Player.Position = GlobalPosition; + GameSceneNodeHolder.Player.GlobalPosition = GlobalPosition; GameSceneNodeHolder.Player.Revive(GameSceneNodeHolder.Player.MaxHp); return; } @@ -60,7 +60,9 @@ public partial class PlayerSpawn : Marker2D return; } - NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(playerNode, this), playerNode); + //The player's parent node must be GameSceneNodeHolder PlayerContainer. + //玩家的父节点必须是GameSceneNodeHolder.PlayerContainer。 + NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.PlayerContainer, playerNode); var itemContainer = GameSceneNodeHolder.HotBar?.GetItemContainer(); if (itemContainer == null) { @@ -71,8 +73,7 @@ public partial class PlayerSpawn : Marker2D playerNode.ItemContainer = itemContainer; GameSceneNodeHolder.Player = playerNode; - playerNode.Position = GlobalPosition; - LogCat.LogWithFormat("player_spawn_debug", playerNode.ReadOnlyCharacterName, playerNode.Position); + playerNode.GlobalPosition = GlobalPosition; } private void MapGenerationCompleteEvent(MapGenerationCompleteEvent mapGenerationCompleteEvent) diff --git a/scripts/map/events/GameReplayEvent.cs b/scripts/map/events/GameReplayEvent.cs index f9e7de1..835abf1 100644 --- a/scripts/map/events/GameReplayEvent.cs +++ b/scripts/map/events/GameReplayEvent.cs @@ -4,7 +4,4 @@ /// Game replay event /// 游戏重玩事件 /// -public class GameReplayEvent -{ - -} \ No newline at end of file +public class GameReplayEvent; \ No newline at end of file diff --git a/scripts/map/events/MapGenerationStartEvent.cs b/scripts/map/events/MapGenerationStartEvent.cs index e18d7a8..6c1fd5a 100644 --- a/scripts/map/events/MapGenerationStartEvent.cs +++ b/scripts/map/events/MapGenerationStartEvent.cs @@ -4,7 +4,4 @@ /// The map generator starts the event /// 地图生成器启动事件 /// -public class MapGenerationStartEvent -{ - -} \ No newline at end of file +public class MapGenerationStartEvent; \ No newline at end of file diff --git a/scripts/projectile/Projectile.cs b/scripts/projectile/Projectile.cs index be694ce..ec36955 100644 --- a/scripts/projectile/Projectile.cs +++ b/scripts/projectile/Projectile.cs @@ -1,6 +1,3 @@ namespace ColdMint.scripts.projectile; -public partial class Projectile : ProjectileTemplate -{ - -} +public partial class Projectile : ProjectileTemplate;