using System.Collections; using System.Collections.Generic; using System.ComponentModel; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/ItemChest.cs")] public partial class ItemChest : StaticBody2D, Interacteable { [Export(PropertyHint.None, "")] private Texture2D[] tex; [Export(PropertyHint.None, "")] private Sprite2D sprite; [Export(PropertyHint.None, "")] private SaveFile.Flags flag; [Export(PropertyHint.None, "")] private Items.IDs item; [Export(PropertyHint.None, "")] private AudioStream sound; [Export(PropertyHint.None, "")] private int qtd = 1; [Export(PropertyHint.None, "")] private int mesID; [Export(PropertyHint.None, "")] private Items.Type invType; private static readonly string[] invers = new string[4] { Texts.common[41], Texts.common[34], Texts.common[42], Texts.common[43] }; public override void _EnterTree() { if (SaveFile.current.flags.Contains(flag) && sprite != null) { sprite.Texture = tex[1]; } } public void Interact() { Main.inEvent = Coroutine.Start(AddItem()); } private IEnumerator AddItem() { Party.StopMoving(); if (SaveFile.current.flags.Contains(flag)) { TextSystem.GetText("EmptyChest"); } else { Audio.PlaySound(sound); if (sprite != null) { sprite.Texture = tex[1]; } string text = ((invType == Items.Type.Money) ? (qtd + " " + Texts.common[12]) : Texts.items[item].name); TextSystem.SingleText(new Texts.TextBlock[1] { new Texts.TextBlock { text = Texts.common[mesID].Replace("@BREAK@", "\n").Replace("@@", "\n [color=yellow]" + text + ((invType == Items.Type.Money) ? "" : ((qtd > 1) ? (" x" + qtd) : ""))) } }); while (TextSystem.instance.Visible) { yield return null; } if (!Items.CheckFull(invType)) { if (invType != Items.Type.Money) { TextSystem.SingleText(new Texts.TextBlock[1] { new Texts.TextBlock { text = Texts.common[2].Replace("@BREAK@", "\n").Replace("@@", invers[(int)invType]) } }); for (int i = 0; i < qtd; i++) { if (Items.CheckFull(invType)) { break; } Items.AddItem(item, invType); } } else { SaveFile.current.dollars = Mathf.Clamp(SaveFile.current.dollars + qtd, 0, 9999); } SaveFile.current.flags.Add(flag); } else { TextSystem.SingleText(new Texts.TextBlock[1] { new Texts.TextBlock { text = Texts.common[33] } }); if (sprite != null) { sprite.Texture = tex[0]; } } } while (TextSystem.instance.Visible) { yield return null; } } }