Skip to content

Commit

Permalink
#88 battle effect casting fixes (revenge)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin V. Krupovich committed Jun 11, 2023
1 parent 638a7ad commit c11b51d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Run(IEcsSystems systems)

internal void AssignAttacker(int turnEntity)
{
if (!battleService.Value.RoundEntity.Unpack(out var world, out var roundEntity))
if (!battleService.Value.RoundEntity.Unpack(out _, out var roundEntity))
throw new Exception("No Round");

ref var roundInfo = ref roundPool.Value.Get(roundEntity);
Expand All @@ -52,7 +52,7 @@ internal void AssignAttacker(int turnEntity)
turnInfo.Attacker = roundSlot.HeroInstancePackedEntity;

ref var attackerRef = ref attackerRefPool.Value.Add(turnEntity);
attackerRef.HeroInstancePackedEntity = world.PackEntityWithWorld(attackerInstanceEntity);
attackerRef.HeroInstancePackedEntity = roundSlot.HeroInstancePackedEntity;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void Run(IEcsSystems systems)

var relEffectProbeEntity = ecsWorld.Value.NewEntity();
ref var probeComp = ref relEffectProbePool.Value.Add(relEffectProbeEntity);
probeComp.SourceOrigPacked = item.Key.Item1;
probeComp.TargetOrigPacked = item.Key.Item2;
probeComp.TargetOrigPacked = item.Key.Item1;
probeComp.SourceOrigPacked = item.Key.Item2;
probeComp.TargetConfigRefPacked = heroConfigRef.Packed;
probeComp.P2PEntityPacked = item.Value;
probeComp.SubjectState = SubjectState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private bool MarkDeadHero<T>(int turnEntity) where T : struct, IPackedWithWorldR
if (hpComp.Value > 0)
return false;

deadTagPool.Value.Add(heroInstanceEntity);
if (!deadTagPool.Value.Has(heroInstanceEntity))
deadTagPool.Value.Add(heroInstanceEntity);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Leopotam.EcsLite;
using Leopotam.EcsLite.Di;
using System;
using UnityEngine;

namespace Assets.Scripts.ECS.Systems
{
Expand Down Expand Up @@ -46,6 +47,11 @@ public void Run(IEcsSystems systems)

// registering effect for the hero affected (in the battle world, to make it handy when needed)
ref var attackerRef = ref attackerRefPool.Value.Get(turnEntity);
if (attackerRef.Packed.Unpack(out var world, out var attackerEntity))
{
var np = world.ReadValue<NameValueComp<NameTag>, string>(attackerEntity);
Debug.Log($"Atatcker is {np}");
}
effect.EffectFocus = attackerRef.Packed;

var revengeEntity = ecsWorld.Value.NewEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Assets.Scripts.Services;
using Leopotam.EcsLite;
using Leopotam.EcsLite.Di;
using UnityEngine;

namespace Assets.Scripts.ECS.Systems
{
Expand Down Expand Up @@ -44,13 +45,23 @@ public void Run(IEcsSystems systems)
{
ref var revengeComp = ref revengePool.Value.Get(entity);
var packedRevenger = revengeComp.RevengeBy;
if (!revengeComp.RevengeBy.Unpack(out _, out var revengerEntity))
if (!revengeComp.RevengeBy.Unpack(out _, out var revengerEntity) ||
!revengeComp.RevengeFor.Unpack(out _, out var revengedEntity) )
throw new Exception($"Stale revenger entity");

Debug.Log(
$"Revenger: {world.ReadValue<NameValueComp<NameTag>, string>(revengerEntity)}" +
$"For: {world.ReadValue<NameValueComp<NameTag>, string>(revengedEntity)}");

if (retiredTagPool.Value.Has(revengerEntity))
continue; // died hero can't revenge

var idx = buffer.FindIndex(x => x.HeroInstancePackedEntity.EqualsTo(packedRevenger));
if (idx != 0)
Debug.Log("Reordering the round queue for the revenge");
else
Debug.Log("No need to reorder the round queue");

if (idx < 0)
{
RoundSlotInfo slotInfo = new ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ object val(int row, int cell)
for (int i = 0; i < heroCount; i++)
{
var heroId = i;
var row = i + 2;
var heroRow = i * 2 + 2;
for (int j = 0; j < stateCount; j++)
{
var subjectState = j switch
{
0 => RelationSubjectState.Attacking,
_ => RelationSubjectState.BeingAttacked
};
var row = heroRow + j;

for (int k = 1; k < relationStateCount * 2; k += 2)
{
Expand Down

0 comments on commit c11b51d

Please sign in to comment.