private static void OnSpellTargetSelected(Target?targetOpt)
 {
     if (targetOpt.HasValue)
     {
         Target value = targetOpt.Value;
         s_castTargetContext.SelectTarget(value);
         int selectedTargetCount = s_castTargetContext.selectedTargetCount;
         if (selectedTargetCount == 1)
         {
             FightCastManager.OnUserActionEnd?.Invoke(FightCastState.Targeting);
         }
         if (selectedTargetCount >= s_castTargetContext.expectedTargetCount)
         {
             s_castTargetContext.SendCommand();
             FightCastManager.OnUserActionEnd?.Invoke(FightCastState.Casting);
         }
         else
         {
             FightMap.current.SetTargetingPhase(s_castTargetDefinition.EnumerateTargets(s_castTargetContext));
         }
     }
     else
     {
         StopCastingSpell(cancelled: true);
     }
 }
        public static bool StartCastingSpell(PlayerStatus casterStatus, SpellStatus spellStatus)
        {
            if (s_currentCastType != 0)
            {
                Log.Error($"Tried to start casting a spell while current cast type is {s_currentCastType}", 59, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightCastManager.cs");
                return(false);
            }
            SpellDefinition definition = spellStatus.definition;

            if (null == definition)
            {
                Log.Error("Tried to start casting a spell without a loaded definition.", 66, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightCastManager.cs");
                return(false);
            }
            ICastTargetDefinition castTarget = definition.castTarget;

            if (castTarget == null)
            {
                Log.Error("Tried to cast a spell that has no cast target definition.", 73, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightCastManager.cs");
                return(false);
            }
            CastTargetContext    castTargetContext = castTarget.CreateCastTargetContext(FightStatus.local, casterStatus.id, DynamicValueHolderType.Spell, definition.get_id(), spellStatus.level, spellStatus.instanceId);
            IReadOnlyList <Cost> costs             = definition.costs;
            int count = costs.Count;

            for (int i = 0; i < count; i++)
            {
                if (costs[i].CheckValidity(casterStatus, castTargetContext) != 0)
                {
                    Log.Error("Tried to cast a spell but one cost requirement is not met.", 86, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightCastManager.cs");
                    return(false);
                }
            }
            FightMap current = FightMap.current;

            if (null != current)
            {
                FightMap fightMap = current;
                fightMap.onTargetChanged = (Action <Target?, CellObject>)Delegate.Combine(fightMap.onTargetChanged, new Action <Target?, CellObject>(OnSpellTargetChanged));
                FightMap fightMap2 = current;
                fightMap2.onTargetSelected = (Action <Target?>)Delegate.Combine(fightMap2.onTargetSelected, new Action <Target?>(OnSpellTargetSelected));
                current.SetTargetingPhase(castTarget.EnumerateTargets(castTargetContext));
            }
            s_currentCastType      = CurrentCastType.Spell;
            s_playerCasting        = casterStatus;
            s_spellBeingCast       = spellStatus;
            s_castTargetDefinition = castTarget;
            s_castTargetContext    = castTargetContext;
            ShowSpellCostsPreview();
            return(true);
        }
Example #3
0
        private static bool HasSpellValidTargets(PlayerStatus casterStatus, SpellStatus spellStatus)
        {
            SpellDefinition definition = spellStatus.definition;

            if (null == definition)
            {
                return(false);
            }
            ICastTargetDefinition castTarget = definition.castTarget;

            if (castTarget == null)
            {
                return(false);
            }
            CastTargetContext castTargetContext = castTarget.CreateCastTargetContext(FightStatus.local, casterStatus.id, DynamicValueHolderType.Spell, definition.get_id(), spellStatus.level, spellStatus.instanceId);

            return(castTarget.EnumerateTargets(castTargetContext).GetEnumerator().MoveNext());
        }