working on charging and quick attacks

This commit is contained in:
2025-07-31 09:04:16 +02:00
parent 407454555f
commit a0c2a389be
34 changed files with 7683 additions and 289 deletions

View File

@@ -1,53 +0,0 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Simulation;
using RebootReality.jelycho.Player;
namespace RebootReality.jelycho.Items {
public class EggChargeAction : IItemChargeAction {
static readonly Logger s_Logger = new Logger(nameof(EggChargeAction));
public bool OnChargeStart(Actor user, ItemActor itemActor) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return false;
}
if (itemActor.Config.itemType != ItemType.Egg) {
s_Logger.Error($"Item {itemActor.name} is not an egg, cannot charge.");
return false;
}
s_Logger.Info($"Begin charging egg: {itemActor.name} by {user.name}");
return true;
}
public void OnChargeUpdate(Actor user, ItemActor itemActor, float chargeProgress) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return;
}
// Here you can implement the logic for updating the charge progress, e.g. visual effects
s_Logger.Info($"Charging egg: {itemActor.name} by {user.name}, progress: {chargeProgress * 100}%");
}
public void OnChargeEnd(Actor user, ItemActor itemActor, float chargeProgress) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return;
}
s_Logger.Info($"Finished charging egg: {itemActor.name} by {user.name}, final progress: {chargeProgress * 100}%");
}
public void OnChargeCancel(Actor user, ItemActor itemActor) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return;
}
s_Logger.Info($"Charging egg: {itemActor.name} by {user.name} was cancelled.");
}
}
}

View File

@@ -0,0 +1,20 @@
using RebootKit.Engine.Simulation;
namespace RebootReality.jelycho.Items {
public class HeavySlashAttackChargeAttack : IItemChargeAction {
public bool OnChargeStart(Actor user, ItemActor itemActor) {
return true;
}
public bool OnChargeUpdate(Actor user, ItemActor itemActor, float chargeProgress) {
return true;
}
public bool OnChargeEnd(Actor user, ItemActor itemActor, float chargeProgress) {
return true;
}
public void OnChargeCancel(Actor user, ItemActor itemActor) {
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 281ce87013154d44872e7b170e4d375c
timeCreated: 1753934000

View File

@@ -4,29 +4,41 @@ using RebootKit.Engine.Simulation;
using UnityEngine;
namespace RebootReality.jelycho.Items {
public enum ItemType {
Neutral = 0,
Egg = 1,
Sword = 2,
}
public interface IItemChargeAction {
bool OnChargeStart(Actor user, ItemActor itemActor);
void OnChargeUpdate(Actor user, ItemActor itemActor, float chargeProgress);
void OnChargeEnd(Actor user, ItemActor itemActor, float chargeProgress);
bool OnChargeUpdate(Actor user, ItemActor itemActor, float chargeProgress);
bool OnChargeEnd(Actor user, ItemActor itemActor, float chargeProgress);
void OnChargeCancel(Actor user, ItemActor itemActor);
}
public interface IItemQuickAttackAction {
void Attack(Actor attacker, ItemActor itemActor);
}
[Serializable]
public class ItemConfig {
public ItemType itemType = ItemType.Neutral;
public Sprite icon;
[MaxLength(32)] public string characterEquippedMountSlotName = "hand_right";
[Header("Character Animations Names")]
public string idleAnimation;
public string chargingAnimation;
public string chargedUseAnimation;
public string[] quickAttacksAnimations;
public string blockAnimation;
[Header("Quick Attack")]
public bool canQuickAttack = false;
[SerializeReference] public IItemQuickAttackAction quickAttackAction;
[Header("Block")]
public bool canBlock = false;
[Header("Chargeable")]
public bool isChargeable = false;
public float minChargeDuration = 0.1f;
public float minChargeDuration = 0.5f;
public float maxChargeDuration = 1.0f;
public float chargeCooldown = 1.0f;
[SerializeReference] public IItemChargeAction chargeAction;

View File

@@ -0,0 +1,31 @@
using RebootKit.Engine.Simulation;
using RebootReality.jelycho.Enemies;
using RebootReality.jelycho.Player;
using UnityEngine;
namespace RebootReality.jelycho.Items {
public class ItemQuickAttackAction : IItemQuickAttackAction {
static readonly Collider[] s_CollidersBuffer = new Collider[512];
public void Attack(Actor attacker, ItemActor itemActor) {
PlayerActor playerActor = attacker as PlayerActor;
if (playerActor == null) {
return;
}
Vector3 attackPosition = playerActor.GetAttackPosition();
int count = Physics.OverlapSphereNonAlloc(attackPosition, 3.0f, s_CollidersBuffer);
for (int i = 0; i < count; ++i) {
if (s_CollidersBuffer[i].TryGetComponent(out IKillable killable)) {
Actor killableActor = killable as Actor;
if (killableActor == attacker) {
continue;
}
playerActor.DealDamage(killable);
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 05afb452f53145848b90465de1a40e30
timeCreated: 1753943558

View File

@@ -0,0 +1,52 @@
using RebootKit.Engine.Main;
using RebootKit.Engine.Simulation;
using RebootReality.jelycho.Player;
using UnityEngine;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootReality.jelycho.Items {
public class SpawnBeaconChargeAction : IItemChargeAction {
static readonly Logger s_Logger = new Logger(nameof(SpawnBeaconChargeAction));
public bool OnChargeStart(Actor user, ItemActor itemActor) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return false;
}
return true;
}
public bool OnChargeUpdate(Actor user, ItemActor itemActor, float chargeProgress) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return false;
}
return true;
}
public bool OnChargeEnd(Actor user, ItemActor itemActor, float chargeProgress) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return false;
}
if (RR.World.Context is WorldContext worldContext) {
if (player.TryGetBeaconPosition(out Vector3 beaconPosition)) {
worldContext.BaseManager.TrySpawnBeacon(beaconPosition);
return true;
}
}
return false;
}
public void OnChargeCancel(Actor user, ItemActor itemActor) {
PlayerActor player = user as PlayerActor;
if (player == null) {
return;
}
}
}
}