private async void LoadEnemy(string enemyDataName) { var data = Autoload.Get <Data>(); if (!data.enemyData.ContainsKey(enemyDataName)) { GD.PushError($"Enemy data for {enemyDataName} not found"); return; } enemyName = enemyDataName; Stat = data.enemyData[enemyDataName]; moveSpeed = data.GetLerpedSpeedStat(Stat.MoveSpeed, MIN_SPEED, MAX_SPEED); battleTexture = new AtlasTexture { Atlas = GD.Load <Texture>(string.Format(BattleSpritePath, enemyDataName.ToLower())) }; if (sprite == null || stateMachine == null) { await ToSignal(this, "ready"); } sprite.Texture = GD.Load <Texture>(string.Format(OverworldSpritePath, enemyDataName.ToLower())); stateMachine.behaviour = GD.Load <AI_Behaviour>(string.Format(AIResourcePath, Stat.AiType.ToLower())); EmitSignal(nameof(StatsLoaded)); }
private void SpawnEnemy(EnemySpawn enemySpawn) { if (enemySpawn.enemies.Length == 0) { GD.PushWarning( $"{enemySpawn} enemy spawn has no enemy names attached."); return; } if (enemySpawn.enemyNumber <= 0) { GD.PushWarning( $"{enemySpawn} enemy spawn's enemyNumber not greater than 0"); return; } for (var i = 0; i < enemySpawn.enemyNumber; i++) { var enemy = (BaseEnemy)_baseEnemyScene.Instance(); var safe = false; var enemyName = enemySpawn.enemies.RandomElement(); if (string.IsNullOrWhiteSpace(enemyName)) { GD.PushError( $"{enemySpawn.Name} enemy spawn has a null enemy attached"); return; } var data = Autoload.Get <Data>(); if (!data.enemyData.ContainsKey(enemyName)) { GD.PushError( $"{enemySpawn} enemy spawn has a {enemyName} enemy with no data attached."); return; } enemy.OnDependency = (ref BaseEnemy.EnemyDependencies dependency) => { dependency.EnemyName = enemyName; dependency.PlayerInstance = _player; }; while (!safe) { enemy.Position = enemySpawn.GetRandomGlobalPosition(); _map.CallDeferred("add_child", enemy); safe = enemy.IsInAllowedTile(); if (!safe) { enemy.QueueFree(); } } enemy.Connect(nameof(BaseEnemy.Died), this, nameof(OnEnemy_Death), new Array { enemySpawn }); } }
private void UpdateCharacters() { var saveData = SaveManager.SaveData; foreach (var keyValuePair in Autoload.Get <Data>().characterData) { var characterName = keyValuePair.Key; var characterRecord = keyValuePair.Value; if (characterRecord.guildLevel > saveData.GuildLevel) { continue; } var character = (Character)CharacterResource.Instance(); _characters.AddChild(character); character.characterName = characterName; if (!character.UpdateCharacter()) { character.QueueFree(); continue; } character.characterButton.Connect("pressed", this, nameof(OnCharacter_Pressed), new Array { character }); } }
public void OnItem_MouseEntered(string itemName) { if (string.IsNullOrWhiteSpace(itemName)) { GD.PushError("Item name must not be empty"); return; } var data = Autoload.Get <Data>(); if (!data.itemData.ContainsKey(itemName)) { GD.PushError($"Item name {itemName} not found"); return; } var itemRecord = data.itemData[itemName]; var itemType = itemRecord.type; _itemNameLabel.Text = itemName; _background.Texture = GetItemTypeBackground(itemType); switch (itemType) { case "item": _damageMargin.Visible = false; _healthGainedLabel.Visible = false; break; case "weapon": _damageMargin.Visible = true; _healthGainedMargin.Visible = false; _quickDamageLabel.Text = $"{itemRecord.quickDamage}"; _heavyDamageLabel.Text = $"{itemRecord.heavyDamage}"; _counterDamageLabel.Text = $"{itemRecord.counterDamage}"; break; case "usable": _damageMargin.Visible = false; _healthGainedMargin.Visible = true; _healthGainedLabel.Text = $"{itemRecord.healthGained}"; break; case "armor": _damageMargin.Visible = false; _healthGainedMargin.Visible = true; _healthGainedLabel.Text = $"{itemRecord.healthAdded}"; break; default: throw new ArgumentOutOfRangeException(); } _tween.InterpolateProperty(this, "rect_position", RectPosition, new Vector2(RectPosition.x, BOTTOM_POS_Y), ANIMATION_DURATION, Tween.TransitionType.Cubic, Tween.EaseType.Out); _tween.Start(); popupToBeVisible = true; }
public void DropItems(string enemyName, Player playerInstance) { _playerInstance = playerInstance; var enemyRecord = Autoload.Get <Data>().enemyData[enemyName]; var coinsDropped = (int)GD.RandRange( enemyRecord.CoinDropAmount * MIN_COIN_DROP, enemyRecord .CoinDropAmount * MAX_COIN_DROP + 1); if (coinsDropped <= 0 && enemyRecord.CoinDropAmount > 0) { coinsDropped = 1; } _coinAmountLabel.Text = $"{coinsDropped}"; _playerInstance.Coins += coinsDropped; foreach (Node child in _itemsDroppedGrid.GetChildren()) { child.QueueFree(); } var items = new Dictionary <string, float>(); if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop1)) { items.Add(enemyRecord.ItemDrop1, enemyRecord.ItemDrop1Chance); } if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop2)) { items.Add(enemyRecord.ItemDrop2, enemyRecord.ItemDrop2Chance); } if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop3)) { items.Add(enemyRecord.ItemDrop3, enemyRecord.ItemDrop3Chance); } for (var i = 0; i < enemyRecord.MaxItemDropped; i++) { var chance = Utility.Random.NextDouble(); foreach (var item in items) { if (chance < item.Value) { var itemDropped = ItemDroppedResource.Instance(); itemDropped.GetNode <TextureRect>("Item").Texture = Utility.GetInventoryItemResource(item.Key); _itemsDroppedGrid.AddChild(itemDropped); playerInstance.Inventory.Add(item.Key); } } } playerInstance.hudMargin.Visible = false; margin.Visible = true; _autoCloseTimer.Start(); }
private async void OnSelect_Pressed() { AudioSystem.StopAllMusic(); SaveManager.SaveData.CharacterName = selectedCharacterName; var transitionParams = new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.2f); await Autoload.Get <Transitions>() .ChangeSceneDoubleTransition(WORLD_SCENE_PATH, transitionParams); }
private async void OnDoorDetection_BodyEntered(KinematicBody2D body) { if (body.IsInGroup("player")) { AudioSystem.PlaySFX(AudioSystem.SFXCollection.GuildHallEnter); await Autoload.Get <Transitions>().ChangeSceneDoubleTransition (WorldScenePath, new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.3f)); } }
private async void GoToMainMenu() { goingToMainMenu = true; var transitionParams = new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.15f); await Autoload.Get <Transitions>() .ChangeSceneDoubleTransition(MainMenuScenePath, transitionParams); Autoload.Get <PaletteSwap>().Enabled = true; }
private async void GoToCharacterSelector() { AudioSystem.StopAllMusic(); _changingScene = true; var transitionParams = new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.2f); var transitions = Autoload.Get <Transitions>(); await transitions.ChangeSceneDoubleTransition(CharacterSelectionScenePath, transitionParams); }
private async void OnDoorDetection_BodyEntered(KinematicBody2D body) { if (body.IsInGroup("player")) { var offset = new Vector2(0, 5); SaveManager.SaveData.WorldPosition = _player.Position + offset; AudioSystem.PlaySFX(AudioSystem.SFXCollection.GuildHallEnter); var transitionParams = new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.3f); await Autoload.Get <Transitions>() .ChangeSceneDoubleTransition(GuildHallScenePath, transitionParams); } }
public void TakeDamage(int damage, string damageType) { GD.Print($"{CharacterInstance.Name} TAKE DAMAGE: {damage} type {damageType}"); EmitSignal(nameof(DamageTaken), damage, damageType); if (CharacterInstance.statusEffects.ContainsKey("Frozen") && damageType == "Fire") { CharacterInstance.statusEffects.Remove("Frozen"); } CharacterInstance.Health -= damage; if (CharacterInstance.Health <= 0) { CharacterInstance.Health = 0; } hitCombo = 0; switch (CharacterInstance) { case Player _: AudioSystem.PlaySFX(AudioSystem.SFXCollection.BattleHurtPlayer); break; case BaseEnemy enemy: { var enemyRecord = Autoload.Get <Data>().enemyData[enemy.enemyName]; if (AudioSystem.SFXCollection.TryGetValue( $"BattleHurt{enemyRecord.Race}", out var sfx)) { AudioSystem.PlaySFX(sfx); } else { GD.PrintErr($"No SFX found for {enemyRecord.Race} race"); } break; } } }
private async void OnUse_Pressed() { AudioSystem.PlaySFX(AudioSystem.SFXCollection.InventoryItemUsed); var data = Autoload.Get <Data>().itemData; if (!data.ContainsKey(selectedItem)) { return; } var itemRecord = data[selectedItem]; var selectedItemType = itemRecord.type; if (selectedItemType == "usable") { if (playerInstance.Health >= playerInstance.maxHealth) { _confirmUsePopup.Visible = true; var yesPressed = (bool)(await ToSignal(this, nameof(YesOrNoPressed)))[0]; _confirmUsePopup.Visible = false; if (!yesPressed) { return; } } else { playerInstance.Health = Mathf.Min( playerInstance.Health + itemRecord.healthGained, playerInstance.maxHealth); } playerInstance.Inventory.Remove(selectedItem); EmitSignal(nameof(ItemUsed), selectedItem); Visible = false; } else { GD.PushError("The use button was pressed for a non-usable item"); } }
private void OnEquip_Pressed() { AudioSystem.PlaySFX(AudioSystem.SFXCollection.InventoryItemEquipped); var data = Autoload.Get <Data>().itemData; if (!data.ContainsKey(selectedItem)) { return; } var itemRecord = data[selectedItem]; var selectedItemType = itemRecord.type; switch (selectedItemType) { case "weapon": playerInstance.EquippedWeapon = selectedItem; EmitSignal(nameof(EquippedWeaponChanged)); _equipButton.Visible = false; break; case "armor": if (!string.IsNullOrWhiteSpace(playerInstance.EquippedArmor)) { var oldArmorData = data[playerInstance.EquippedArmor]; playerInstance.Health -= oldArmorData.healthAdded; } playerInstance.EquippedArmor = selectedItem; playerInstance.maxHealth = SaveData.DefaultHealth + itemRecord.healthAdded; playerInstance.Health += itemRecord.healthAdded; EmitSignal(nameof(EquippedArmorChanged)); _equipButton.Visible = false; break; default: GD.PushError( "The equip button was pressed for a non-equippable item."); break; } }
private async void GoToCharacterSelector() { if (!_introSFXPlayed) { _introSFXPlayer.Stop(); _introSFXPlayer.QueueFree(); PlayTitleScreenMusic(); } AudioSystem.PlaySFX(AudioSystem.SFXCollection.TitleScreenKeyPressed); _changingScene = true; var transitionParams = new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.2f); var transitions = Autoload.Get <Transitions>(); await transitions.ChangeSceneDoubleTransition(CharacterSelectionScenePath, transitionParams); }
private async void GameOver() { _player.isDead = true; var saveData = SaveManager.SaveData; saveData.WorldPosition = SaveData.DefaultWorldPosition; saveData.Coins = SaveData.DefaultCoins; saveData.Inventory = SaveData.DefaultInventory; saveData.EquippedWeapon = SaveData.DefaultWeapon; saveData.EquippedArmor = SaveData.DefaultArmor; saveData.MaxHealth = SaveData.DefaultHealth; saveData.Health = SaveData.DefaultHealth; _player.Health = SaveData.DefaultHealth; AudioSystem.StopAllMusic(); await Autoload.Get <Transitions>().ChangeSceneDoubleTransition( GameOverScenePath, new Transitions.TransitionParams( Transitions.TransitionType.ShrinkingCircle, 0.2f)); }
public void OnItem_Pressed(InventoryItem item, Player player) { var itemName = item.itemName; selectedItem = itemName; playerInstance = player; Visible = true; AudioSystem.PlaySFX(AudioSystem.SFXCollection.PauseMenuItemPressed); EmitSignal(nameof(DetailedItemInfoMenuAppeared)); _nameLabel.Text = itemName; _itemIcon.Texture = GD.Load <Texture>(string.Format(InventorySprite, itemName.ToLower().Replace(" ", "_"))); var data = Autoload.Get <Data>(); if (!data.itemData.ContainsKey(itemName)) { return; } var itemRecord = data.itemData[itemName]; var itemType = itemRecord.type; switch (itemType) { case "item": _damageValues.Visible = false; _equipButton.Visible = false; _useButton.Visible = false; _healthGainedHBox.Visible = false; break; case "weapon": _damageValues.Visible = true; _equipButton.Visible = playerInstance.EquippedWeapon != itemName; _useButton.Visible = false; _healthGainedHBox.Visible = false; _quickDamageLabel.Text = $"{itemRecord.quickDamage}"; _heavyDamageLabel.Text = $"{itemRecord.heavyDamage}"; _counterDamageLabel.Text = $"{itemRecord.counterDamage}"; _quickTypeIcon.Texture = GetDamageTypeIcon(itemRecord.quickDamageType); _heavyTypeIcon.Texture = GetDamageTypeIcon(itemRecord.heavyDamageType); _counterTypeIcon.Texture = GetDamageTypeIcon(itemRecord.counterDamageType); _quickStatusIcon.Texture = GetDamageTypeStatusIcon(itemRecord.quickStatusEffect); _quickStatusEffectChanceLabel.Text = itemRecord.quickStatusEffect == "none" ? string.Empty : $"{itemRecord.quickEffectChance}"; _heavyStatusIcon.Texture = GetDamageTypeStatusIcon(itemRecord.heavyStatusEffect); _heavyStatusEffectChanceLabel.Text = itemRecord.heavyStatusEffect == "none" ? string.Empty : $"{itemRecord.heavyEffectChance}"; _counterStatusIcon.Texture = GetDamageTypeStatusIcon(itemRecord.counterStatusEffect); _counterStatusEffectChanceLabel.Text = itemRecord.counterStatusEffect == "none" ? string.Empty : $"{itemRecord.counterEffectChance}"; break; case "usable": _damageValues.Visible = false; _equipButton.Visible = false; _useButton.Visible = true; _healthGainedHBox.Visible = true; _healthGainedValueLabel.Text = $"{itemRecord.healthGained}"; break; case "armor": _damageValues.Visible = false; _equipButton.Visible = playerInstance.EquippedArmor != itemName; _useButton.Visible = false; _healthGainedHBox.Visible = true; _healthGainedValueLabel.Text = $"{itemRecord.healthAdded}"; break; default: throw new ArgumentOutOfRangeException(); } }
public override void _Ready() { Autoload.Get <PaletteSwap>().Enabled = false; }