No backpack nesting backpack.

禁止背包嵌套背包。
This commit is contained in:
Cold-Mint 2024-06-25 22:11:19 +08:00
parent d587c4fc01
commit dea683dbc5
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
12 changed files with 38 additions and 42 deletions

View File

@ -20,7 +20,7 @@ public static class Config
/// </summary>
public const string Patrol = "Patrol";
}
/// <summary>
/// <para>Loot table ID</para>
/// <para>战利品表ID</para>
@ -90,7 +90,7 @@ public static class Config
/// <para>抛出的物品击中敌人后减少的速度百分比</para>
/// </summary>
public const float ThrownItemsHitEnemiesReduceSpeedByPercentage = 0.5f;
/// <summary>
/// <para>How much blood does a heart represent</para>
/// <para>一颗心代表多少血量</para>

View File

@ -25,6 +25,7 @@ public partial class BehaviorNode : Node2D
{
return;
}
Root.Execute(isPhysicsProcess, delta);
}
}

View File

@ -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;
/// </summary>
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到武器

View File

@ -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<PackedScene>("res://prefab/ui/FloatLabel.tscn");
_parabola = GetNode<Line2D>("Parabola");
_platformDetectionRayCast2D = GetNode<RayCast2D>("PlatformDetectionRayCast");

View File

@ -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>? 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;
}
}
}

View File

@ -85,7 +85,7 @@ public partial class ItemSlotNode : MarginContainer
return false;
}
return _item == null;
return CanAddItem(item);
}
/// <summary>
@ -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);
}
/// <summary>
/// <para>Whether to place a backpack in the current slot</para>
/// <para>当前槽位是否允许放置背包</para>
/// </summary>
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;
}

View File

@ -30,7 +30,7 @@ public partial class Packsack : PickAbleTemplate
_packsackUi = NodeUtils.InstantiatePackedScene<PacksackUi>(_packedScene);
if (_packsackUi != null)
{
NodeUtils.CallDeferredReparent(this, _packsackUi);
NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(_packsackUi, this), _packsackUi);
_packsackUi.Title = Name;
_packsackUi.ItemContainer = ItemContainer;
}

View File

@ -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()

View File

@ -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)

View File

@ -4,7 +4,4 @@
/// <para>Game replay event</para>
/// <para>游戏重玩事件</para>
/// </summary>
public class GameReplayEvent
{
}
public class GameReplayEvent;

View File

@ -4,7 +4,4 @@
/// <para>The map generator starts the event</para>
/// <para>地图生成器启动事件</para>
/// </summary>
public class MapGenerationStartEvent
{
}
public class MapGenerationStartEvent;

View File

@ -1,6 +1,3 @@
namespace ColdMint.scripts.projectile;
public partial class Projectile : ProjectileTemplate
{
}
public partial class Projectile : ProjectileTemplate;