mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 06:05:55 +00:00
Item Effects system
This commit is contained in:
parent
96acadf34c
commit
dae952af8b
15 changed files with 255 additions and 84 deletions
|
|
@ -36,6 +36,7 @@ public partial class PlayerFSMItemUseModule : ModuleBase<PlayerState, CharacterB
|
|||
}
|
||||
|
||||
private IStateMachine<PlayerState, CharacterBody2D> _machine;
|
||||
public IStateMachine<PlayerState, CharacterBody2D> Machine => _machine;
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
{
|
||||
|
|
@ -46,91 +47,96 @@ public partial class PlayerFSMItemUseModule : ModuleBase<PlayerState, CharacterB
|
|||
private void UseItem(LootItem item, int totalcount)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
GD.Print("Used spiderbomb in player");
|
||||
switch (item.Item)
|
||||
{
|
||||
case ItemTypes.KeycardRed:
|
||||
break;
|
||||
case ItemTypes.KeycardBlue:
|
||||
break;
|
||||
case ItemTypes.KeycardGreen:
|
||||
break;
|
||||
case ItemTypes.Ammo:
|
||||
break;
|
||||
case ItemTypes.Medkit:
|
||||
Heal(item);
|
||||
break;
|
||||
case ItemTypes.FrogBomb:
|
||||
SpawnSpiderBomb(item);
|
||||
break;
|
||||
case ItemTypes.Bomb:
|
||||
SpawnBomb(item);
|
||||
break;
|
||||
case ItemTypes.Mine:
|
||||
break;
|
||||
case ItemTypes.Battery:
|
||||
RechargeShield(item);
|
||||
break;
|
||||
case ItemTypes.Weapon:
|
||||
break;
|
||||
case ItemTypes.Power:
|
||||
break;
|
||||
case ItemTypes.Points:
|
||||
break;
|
||||
case ItemTypes.Credits:
|
||||
break;
|
||||
case ItemTypes.KeyItem:
|
||||
break;
|
||||
}
|
||||
GD.Print($"Used {item.ItemName} in player");
|
||||
|
||||
item.ItemEffect?.Execute(this, item);
|
||||
|
||||
return;
|
||||
|
||||
// switch (item.Item)
|
||||
// {
|
||||
// case ItemTypes.KeycardRed:
|
||||
// break;
|
||||
// case ItemTypes.KeycardBlue:
|
||||
// break;
|
||||
// case ItemTypes.KeycardGreen:
|
||||
// break;
|
||||
// case ItemTypes.Ammo:
|
||||
// break;
|
||||
// case ItemTypes.Medkit:
|
||||
// Heal(item);
|
||||
// break;
|
||||
// case ItemTypes.FrogBomb:
|
||||
// SpawnSpiderBomb(item);
|
||||
// break;
|
||||
// case ItemTypes.Bomb:
|
||||
// SpawnBomb(item);
|
||||
// break;
|
||||
// case ItemTypes.Mine:
|
||||
// break;
|
||||
// case ItemTypes.Battery:
|
||||
// RechargeShield(item);
|
||||
// break;
|
||||
// case ItemTypes.Weapon:
|
||||
// break;
|
||||
// case ItemTypes.Power:
|
||||
// break;
|
||||
// case ItemTypes.Points:
|
||||
// break;
|
||||
// case ItemTypes.Credits:
|
||||
// break;
|
||||
// case ItemTypes.KeyItem:
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void SpawnBomb(LootItem item)
|
||||
{
|
||||
GD.Print("Spawned bomb");
|
||||
}
|
||||
|
||||
private void Heal(LootItem item)
|
||||
{
|
||||
Health.CurrentResource += Mathf.CeilToInt(Health.MaxResource * 25 / 100);
|
||||
}
|
||||
|
||||
private void RechargeShield(LootItem item)
|
||||
{
|
||||
Shield.CurrentResource += Mathf.CeilToInt(Health.MaxResource * 25 / 100);
|
||||
}
|
||||
|
||||
private void SpawnSpiderBomb(LootItem item)
|
||||
{
|
||||
//var bullet = item.WeaponData.BulletData.BulletScene.Instantiate<Bullet>();
|
||||
//bullet.Initialize(item.WeaponData.BulletData.MakeBullet(this.GlobalPosition, 1,0, 0), GameManager.Instance);
|
||||
|
||||
|
||||
//InventoryManager.Instance.RemoveItem(item.ItemKey, 1);
|
||||
// emit projectile
|
||||
var bullet = this.CreateChildOf<Bullet>(GameManager.Instance.BulletsContainer, item.WeaponData.BulletData.BulletScene, this.GlobalPosition);
|
||||
|
||||
var bulletData = item.WeaponData.MakeBullet(this.GlobalPosition);
|
||||
|
||||
bullet.Initialize(bulletData, GameManager.Instance);
|
||||
bullet.SetDirection(FacingDirection);
|
||||
bullet.RotateSpriteDegrees(-90);
|
||||
//bullet.SetDirection(_facingDirection);
|
||||
bullet.Speed = item.WeaponData.BulletData.BulletSpeed;
|
||||
|
||||
_machine.SetState(PlayerState.Controlling);
|
||||
|
||||
//RequestMovementDisable(true);
|
||||
// set camera
|
||||
GameManager.Instance.CameraTargetObject(bullet);
|
||||
// set event destroy
|
||||
bullet.OnDestroy += () =>
|
||||
{
|
||||
GameManager.Instance.CameraTargetPlayer();
|
||||
_machine.SetState(PlayerState.Active);
|
||||
//RequestMovementDisable(false);
|
||||
};
|
||||
}
|
||||
// private void SpawnBomb(LootItem item)
|
||||
// {
|
||||
// GD.Print("Spawned bomb");
|
||||
// }
|
||||
//
|
||||
// private void Heal(LootItem item)
|
||||
// {
|
||||
// Health.CurrentResource += Mathf.CeilToInt(Health.MaxResource * 25 / 100);
|
||||
// }
|
||||
//
|
||||
// private void RechargeShield(LootItem item)
|
||||
// {
|
||||
// Shield.CurrentResource += Mathf.CeilToInt(Health.MaxResource * 25 / 100);
|
||||
// }
|
||||
//
|
||||
// private void SpawnSpiderBomb(LootItem item)
|
||||
// {
|
||||
// //var bullet = item.WeaponData.BulletData.BulletScene.Instantiate<Bullet>();
|
||||
// //bullet.Initialize(item.WeaponData.BulletData.MakeBullet(this.GlobalPosition, 1,0, 0), GameManager.Instance);
|
||||
//
|
||||
//
|
||||
// //InventoryManager.Instance.RemoveItem(item.ItemKey, 1);
|
||||
// // emit projectile
|
||||
// var bullet = this.CreateChildOf<Bullet>(GameManager.Instance.BulletsContainer, item.WeaponData.BulletData.BulletScene, this.GlobalPosition);
|
||||
//
|
||||
// var bulletData = item.WeaponData.MakeBullet(this.GlobalPosition);
|
||||
//
|
||||
// bullet.Initialize(bulletData, GameManager.Instance);
|
||||
// bullet.SetDirection(FacingDirection);
|
||||
// bullet.RotateSpriteDegrees(-90);
|
||||
// //bullet.SetDirection(_facingDirection);
|
||||
// bullet.Speed = item.WeaponData.BulletData.BulletSpeed;
|
||||
//
|
||||
// _machine.SetState(PlayerState.Controlling);
|
||||
//
|
||||
// //RequestMovementDisable(true);
|
||||
// // set camera
|
||||
// GameManager.Instance.CameraTargetObject(bullet);
|
||||
// // set event destroy
|
||||
// bullet.OnDestroy += () =>
|
||||
// {
|
||||
// GameManager.Instance.CameraTargetPlayer();
|
||||
// _machine.SetState(PlayerState.Active);
|
||||
// //RequestMovementDisable(false);
|
||||
// };
|
||||
// }
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
|
|
|
|||
41
Scripts/Resources/ItemEffects/HealEffectResource.cs
Normal file
41
Scripts/Resources/ItemEffects/HealEffectResource.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ItemEffects;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class HealEffectResource : ItemEffectResource
|
||||
{
|
||||
[Export] public float HealAmount { get; private set; } = 10f;
|
||||
[Export] public HealResourceType ResourceType { get; private set; } = HealResourceType.Health;
|
||||
|
||||
public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
|
||||
{
|
||||
return new HealEffectmachine(this, parent, item).Execute();
|
||||
}
|
||||
|
||||
public class HealEffectmachine(HealEffectResource resource, PlayerFSMItemUseModule parent, LootItem item)
|
||||
: IITemEffectMachine
|
||||
{
|
||||
public IITemEffectMachine Execute()
|
||||
{
|
||||
switch (resource.ResourceType)
|
||||
{
|
||||
case HealResourceType.Health:
|
||||
parent.Health.CurrentResource += resource.HealAmount;
|
||||
break;
|
||||
case HealResourceType.Shield:
|
||||
parent.Shield.CurrentResource += resource.HealAmount;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HealResourceType
|
||||
{
|
||||
Health,
|
||||
Shield
|
||||
}
|
||||
}
|
||||
1
Scripts/Resources/ItemEffects/HealEffectResource.cs.uid
Normal file
1
Scripts/Resources/ItemEffects/HealEffectResource.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ppuaa7avtsgq
|
||||
33
Scripts/Resources/ItemEffects/HealPercentEffectResource.cs
Normal file
33
Scripts/Resources/ItemEffects/HealPercentEffectResource.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ItemEffects;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class HealPercentEffectResource : ItemEffectResource
|
||||
{
|
||||
[Export] public float HealPercentage = 25f;
|
||||
[Export] public HealEffectResource.HealResourceType ResourceType { get; private set; } = HealEffectResource.HealResourceType.Health;
|
||||
public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
|
||||
{
|
||||
return new HealPercentEffectmachine(this, parent, item).Execute();
|
||||
}
|
||||
|
||||
public class HealPercentEffectmachine(HealPercentEffectResource resource, PlayerFSMItemUseModule parent, LootItem item) : IITemEffectMachine
|
||||
{
|
||||
public IITemEffectMachine Execute()
|
||||
{
|
||||
switch (resource.ResourceType)
|
||||
{
|
||||
case HealEffectResource.HealResourceType.Health:
|
||||
parent.Health.CurrentResource += Mathf.CeilToInt(parent.Health.MaxResource * resource.HealPercentage / 100);
|
||||
break;
|
||||
case HealEffectResource.HealResourceType.Shield:
|
||||
parent.Shield.CurrentResource += Mathf.CeilToInt(parent.Shield.MaxResource * resource.HealPercentage / 100);
|
||||
break;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bxgjw8wis5l0t
|
||||
8
Scripts/Resources/ItemEffects/IITemEffectMachine.cs
Normal file
8
Scripts/Resources/ItemEffects/IITemEffectMachine.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ItemEffects;
|
||||
|
||||
public interface IITemEffectMachine
|
||||
{
|
||||
public IITemEffectMachine Execute();
|
||||
}
|
||||
1
Scripts/Resources/ItemEffects/IITemEffectMachine.cs.uid
Normal file
1
Scripts/Resources/ItemEffects/IITemEffectMachine.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bb8cess7hkvwg
|
||||
10
Scripts/Resources/ItemEffects/ItemEffectResource.cs
Normal file
10
Scripts/Resources/ItemEffects/ItemEffectResource.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ItemEffects;
|
||||
|
||||
[GlobalClass]
|
||||
public abstract partial class ItemEffectResource : Resource
|
||||
{
|
||||
public abstract IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item);
|
||||
}
|
||||
1
Scripts/Resources/ItemEffects/ItemEffectResource.cs.uid
Normal file
1
Scripts/Resources/ItemEffects/ItemEffectResource.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cmkhe0q83rkmd
|
||||
44
Scripts/Resources/ItemEffects/SpiderbombEffectResource.cs
Normal file
44
Scripts/Resources/ItemEffects/SpiderbombEffectResource.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ItemEffects;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class SpiderbombEffectResource : ItemEffectResource
|
||||
{
|
||||
public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
|
||||
{
|
||||
return new SpiderbombEffectmachine(this, parent, item).Execute();
|
||||
}
|
||||
|
||||
public class SpiderbombEffectmachine(SpiderbombEffectResource resource, PlayerFSMItemUseModule parent, LootItem item) : IITemEffectMachine
|
||||
{
|
||||
public IITemEffectMachine Execute()
|
||||
{
|
||||
var bullet = parent.CreateChildOf<Bullet>(GameManager.Instance.BulletsContainer, item.WeaponData.BulletData.BulletScene, parent.GlobalPosition);
|
||||
|
||||
var bulletData = item.WeaponData.MakeBullet(parent.GlobalPosition);
|
||||
|
||||
bullet.Initialize(bulletData, GameManager.Instance);
|
||||
bullet.SetDirection(parent.FacingDirection);
|
||||
bullet.RotateSpriteDegrees(-90);
|
||||
//bullet.SetDirection(_facingDirection);
|
||||
bullet.Speed = item.WeaponData.BulletData.BulletSpeed;
|
||||
|
||||
parent.Machine.SetState(PlayerState.Controlling);
|
||||
|
||||
//RequestMovementDisable(true);
|
||||
// set camera
|
||||
GameManager.Instance.CameraTargetObject(bullet);
|
||||
// set event destroy
|
||||
bullet.OnDestroy += () =>
|
||||
{
|
||||
GameManager.Instance.CameraTargetPlayer();
|
||||
parent.Machine.SetState(PlayerState.Active);
|
||||
//RequestMovementDisable(false);
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cyipg3seetrxd
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Resources.ItemEffects;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
|
|
@ -9,6 +10,7 @@ public partial class LootItem : Resource
|
|||
[Export] public StringName ItemDescription { get; set; }
|
||||
[Export] public StringName ItemKey { get; set; }
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public ItemEffectResource ItemEffect { get; private set; }
|
||||
[Export] public WeaponResource WeaponData { get; set; }
|
||||
[Export] public int Amount;
|
||||
[Export] public int Max;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue