Exemplo n.º 1
0
        public int GetSpellCooldown(SpellLevelTemplate spell)
        {
            var mostRecentEntry = m_underlyingStack.LastOrDefault(entry => entry.Spell.Id == spell.Id);

            if (mostRecentEntry == null && CurrentRound < spell.InitialCooldown)
            {
                return((int)(spell.InitialCooldown - CurrentRound));
            }

            if (mostRecentEntry == null)
            {
                return(0);
            }

            var elapsedCd = mostRecentEntry.GetElapsedRounds(CurrentRound);

            if (elapsedCd < mostRecentEntry.CooldownDuration)
            {
                return(mostRecentEntry.CooldownDuration - elapsedCd);
            }

            var castsThisRound = m_underlyingStack.Where(entry => entry.Spell.Id == spell.Id && entry.CastRound == CurrentRound).ToArray();

            if (castsThisRound.Length == 0)
            {
                return(0);
            }

            if (spell.MaxCastPerTurn > 0 && castsThisRound.Length >= spell.MaxCastPerTurn)
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 2
0
        public bool CanCastSpell(SpellLevelTemplate spell)
        {
            SpellHistoryEntry spellHistoryEntry = this.m_underlyingStack.LastOrDefault((SpellHistoryEntry entry) => entry.Spell.Id == spell.Id);
            bool result;

            if (spellHistoryEntry == null && (long)this.CurrentRound < (long)((ulong)spell.InitialCooldown))
            {
                result = false;
            }
            else
            {
                if (spellHistoryEntry == null)
                {
                    result = true;
                }
                else
                {
                    if (spellHistoryEntry.IsGlobalCooldownActive(this.CurrentRound))
                    {
                        result = false;
                    }
                    else
                    {
                        SpellHistoryEntry[] array = (
                            from entry in this.m_underlyingStack
                            where entry.Spell.Id == spell.Id && entry.CastRound == this.CurrentRound
                            select entry).ToArray <SpellHistoryEntry>();
                        result = (array.Length == 0 || spell.MaxCastPerTurn <= 0u || (long)array.Length < (long)((ulong)spell.MaxCastPerTurn));
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 public SpellHistoryEntry(SpellHistory history, SpellLevelTemplate spell, FightActor caster, FightActor target, int castRound)
 {
     this.History   = history;
     this.Spell     = spell;
     this.Caster    = caster;
     this.Target    = target;
     this.CastRound = castRound;
 }
Exemplo n.º 4
0
 public SpellHistoryEntry(SpellHistory history, SpellLevelTemplate spell, FightActor caster, FightActor target, int castRound, int?cooldownDuration)
 {
     History            = history;
     Spell              = spell;
     Caster             = caster;
     Target             = target;
     CastRound          = castRound;
     m_cooldownDuration = cooldownDuration;
 }
Exemplo n.º 5
0
        public bool CanCastSpell(SpellLevelTemplate spell, Cell targetedCell)
        {
            SpellHistoryEntry spellHistoryEntry = this.m_underlyingStack.LastOrDefault((SpellHistoryEntry entry) => entry.Spell.Id == spell.Id);
            bool result;

            if (spellHistoryEntry == null && (long)this.CurrentRound < (long)((ulong)spell.InitialCooldown))
            {
                result = false;
            }
            else
            {
                if (spellHistoryEntry == null)
                {
                    result = true;
                }
                else
                {
                    if (spellHistoryEntry.IsGlobalCooldownActive(this.CurrentRound))
                    {
                        result = false;
                    }
                    else
                    {
                        SpellHistoryEntry[] array = (
                            from entry in this.m_underlyingStack
                            where entry.Spell.Id == spell.Id && entry.CastRound == this.CurrentRound
                            select entry).ToArray <SpellHistoryEntry>();
                        if (array.Length == 0)
                        {
                            result = true;
                        }
                        else
                        {
                            if (spell.MaxCastPerTurn > 0u && (long)array.Length >= (long)((ulong)spell.MaxCastPerTurn))
                            {
                                result = false;
                            }
                            else
                            {
                                FightActor target = this.Owner.Fight.GetOneFighter(targetedCell);
                                if (target == null)
                                {
                                    result = true;
                                }
                                else
                                {
                                    int num = array.Count((SpellHistoryEntry entry) => entry.Target != null && entry.Target.Id == target.Id);
                                    result = (spell.MaxCastPerTarget <= 0u || (long)num < (long)((ulong)spell.MaxCastPerTarget));
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public bool UnBoostSpell()
        {
            if (!ByLevel.ContainsKey(CurrentLevel - 1))
            {
                return(false);
            }

            m_level--;
            if (m_record != null)
            {
                m_record.Level = m_level;
            }
            m_currentLevel = ByLevel[m_level];
            return(true);
        }
Exemplo n.º 7
0
        public bool BoostSpell()
        {
            if (!CanBoostSpell())
            {
                return(false);
            }

            m_level++;
            if (m_record != null)
            {
                m_record.Level = m_level;
            }
            m_currentLevel = ByLevel[m_level];
            return(true);
        }
Exemplo n.º 8
0
        public bool BoostSpell()
        {
            bool result;

            if (!this.CanBoostSpell())
            {
                result = false;
            }
            else
            {
                this.m_level       += 1;
                this.m_record.Level = (short)this.m_level;
                this.m_currentLevel = this.ByLevel[(int)this.m_level];
                result = true;
            }
            return(result);
        }
Exemplo n.º 9
0
        public bool UnBoostSpell()
        {
            bool result;

            if (!this.ByLevel.ContainsKey((int)(this.CurrentLevel - 1)))
            {
                result = false;
            }
            else
            {
                this.m_level       -= 1;
                this.m_record.Level = (short)this.m_level;
                this.m_currentLevel = this.ByLevel[(int)this.m_level];
                result = true;
            }
            return(result);
        }
Exemplo n.º 10
0
        public bool CanCastSpell(SpellLevelTemplate spell, Cell targetedCell)
        {
            if (!CanCastSpell(spell))
            {
                return(false);
            }

            var target = Owner.Fight.GetOneFighter(targetedCell);

            if (target == null)
            {
                return(true);
            }

            var castsThisRound    = m_underlyingStack.Where(entry => entry.Spell.Id == spell.Id && entry.CastRound == CurrentRound).ToArray();
            var castsOnThisTarget = castsThisRound.Count(entry => entry.Target != null && entry.Target.Id == target.Id);

            return(spell.MaxCastPerTarget <= 0 || castsOnThisTarget < spell.MaxCastPerTarget);
        }
Exemplo n.º 11
0
        public bool CanCastSpell(SpellLevelTemplate spell)
        {
            if (spell.GlobalCooldown != 0 &&
                Owner.Team.Fighters.OfType <CharacterFighter>().Any(x => x.SpellHistory.GetMostRecentEntry(spell) != null &&
                                                                    x.SpellHistory.GetMostRecentEntry(spell).IsGlobalCooldownActive(CurrentRound)))
            {
                return(false);
            }

            var mostRecentEntry = GetMostRecentEntry(spell);

            //check initial cooldown
            if (mostRecentEntry == null && (CurrentRound - InitialRound) < spell.InitialCooldown)
            {
                return(false);
            }

            if (mostRecentEntry == null)
            {
                return(true);
            }

            if (mostRecentEntry.IsCooldownActive(CurrentRound))
            {
                return(false);
            }

            var castsThisRound = m_underlyingStack.Where(entry => entry.Spell.Id == spell.Id && entry.CastRound == CurrentRound).ToArray();

            if (castsThisRound.Length == 0)
            {
                return(true);
            }

            if (spell.MaxCastPerTurn > 0 && castsThisRound.Length >= spell.MaxCastPerTurn)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
 public static SpellCategory GetSpellCategories(SpellLevelTemplate spellLevel)
 => spellLevel.Effects.Aggregate(SpellCategory.None, (current, effect) => current | GetEffectCategories(effect.EffectId));
Exemplo n.º 13
0
 public void AnalysePossibilities()
 {
     this.Possibilities = new System.Collections.Generic.List <SpellCastInformations>();
     foreach (Spell current in this.Fighter.Spells.Values)
     {
         SpellCategory         spellCategories       = SpellIdentifier.GetSpellCategories(current);
         SpellLevelTemplate    currentSpellLevel     = current.CurrentSpellLevel;
         SpellCastInformations spellCastInformations = new SpellCastInformations(current);
         if ((long)this.Fighter.AP >= (long)((ulong)currentSpellLevel.ApCost) && !currentSpellLevel.StatesForbidden.Any(new Func <int, bool>(this.Fighter.HasState)))
         {
             if (!currentSpellLevel.StatesRequired.Any((int state) => !this.Fighter.HasState(state)) && this.Fighter.SpellHistory.CanCastSpell(current.CurrentSpellLevel))
             {
                 if ((spellCategories & SpellCategory.Summoning) != SpellCategory.None && this.Fighter.CanSummon())
                 {
                     Cell freeAdjacentCell = this.m_environment.GetFreeAdjacentCell();
                     if (freeAdjacentCell == null)
                     {
                         continue;
                     }
                     spellCastInformations.IsSummoningSpell = true;
                     spellCastInformations.SummonCell       = freeAdjacentCell;
                 }
                 else
                 {
                     foreach (FightActor current2 in
                              from fighter in this.Fighter.Fight.Fighters
                              where fighter.IsAlive() && fighter.IsVisibleFor(this.Fighter)
                              select fighter)
                     {
                         int mPToUse;
                         if (this.CanReach(current2, current, out mPToUse) && this.Fighter.SpellHistory.CanCastSpell(current.CurrentSpellLevel, current2.Cell))
                         {
                             spellCastInformations.MPToUse = mPToUse;
                             SpellTarget spellTarget = this.ComputeSpellImpact(current, current2);
                             if (spellTarget != null)
                             {
                                 spellTarget.Target = current2;
                                 if (spellTarget.Damage >= 0.0)
                                 {
                                     spellCastInformations.Impacts.Add(spellTarget);
                                 }
                             }
                         }
                     }
                 }
                 this.Possibilities.Add(spellCastInformations);
             }
         }
     }
     if (Brain.Brain.DebugMode)
     {
         Debug.WriteLine(this.Fighter.Name);
         using (System.Collections.Generic.Dictionary <int, Spell> .ValueCollection.Enumerator enumerator = this.Fighter.Spells.Values.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 Spell spell = enumerator.Current;
                 Debug.WriteLine("Spell {0} ({1}) :: {2}", new object[]
                 {
                     spell.Template.Name,
                     spell.Id,
                     SpellIdentifier.GetSpellCategories(spell)
                 });
                 System.Collections.Generic.IEnumerable <SpellCastInformations> arg_2C4_0 = this.Possibilities;
                 Func <SpellCastInformations, bool> predicate = (SpellCastInformations x) => x.Spell == spell;
                 SpellCastInformations spellCastInformations2 = arg_2C4_0.FirstOrDefault(predicate);
                 if (spellCastInformations2 != null)
                 {
                     if (spellCastInformations2.IsSummoningSpell)
                     {
                         Debug.WriteLine("\tSummon Spell");
                     }
                     else
                     {
                         ObjectDumper objectDumper = new ObjectDumper(8);
                         objectDumper.MemberPredicate = ((System.Reflection.MemberInfo member) => !member.Name.Contains("Target"));
                         ObjectDumper objectDumper2 = objectDumper;
                         Debug.WriteLine("\t{0} Targets", new object[]
                         {
                             spellCastInformations2.Impacts.Count
                         });
                         foreach (SpellTarget spellTarget in spellCastInformations2.Impacts)
                         {
                             Debug.Write(objectDumper2.DumpElement(spellTarget));
                             if (spellTarget.Target != null)
                             {
                                 Debug.WriteLine("\t\tTarget = " + spellTarget.Target + spellTarget.Target.Id.ToString());
                             }
                         }
                     }
                 }
             }
         }
         Debug.WriteLine("");
     }
 }
Exemplo n.º 14
0
 SpellHistoryEntry GetMostRecentEntry(SpellLevelTemplate spell)
 {
     return(m_underlyingStack.LastOrDefault(entry => entry.Spell.SpellId == spell.SpellId));
 }
Exemplo n.º 15
0
 public void RegisterCastedSpell(SpellLevelTemplate spell, FightActor target)
 {
     RegisterCastedSpell(new SpellHistoryEntry(this, spell, Owner, target, CurrentRound, null));
 }
Exemplo n.º 16
0
 public override FightSpellCastCriticalEnum RollCriticalDice(SpellLevelTemplate spell)
 => Character.CriticalMode ? FightSpellCastCriticalEnum.CRITICAL_HIT : base.RollCriticalDice(spell);
Exemplo n.º 17
0
 public void RegisterCastedSpell(SpellLevelTemplate spell, FightActor target)
 {
     this.RegisterCastedSpell(new SpellHistoryEntry(this, spell, this.Owner, target, this.CurrentRound));
 }