public override bool UseWeapon(short cellid)
        {
            var target = Fight.GetFighter(cellid);
            CharacterItemRecord weapon = Client.Character.Inventory.GetEquipedWeapon();

            if (weapon == null)
            {
                UsePunch(cellid);
                return(true);
            }
            WeaponRecord template = WeaponRecord.GetWeapon(weapon.GID);
            FightSpellCastCriticalEnum critical = RollCriticalDice(template);

            Fight.TryStartSequence(this.ContextualId, 2);
            int targetId = target != null ? target.ContextualId : 0;

            Fight.Send(new GameActionFightCloseCombatMessage(0, this.ContextualId, targetId, cellid, (sbyte)critical, false, weapon.GID));
            var effects = template.GetWeaponEffects(critical);

            this.HandleWeaponEffect(cellid, effects, critical);
            this.FighterStats.Stats.ActionPoints -= template.ApCost;
            this.GameActionFightPointsVariation(ActionsEnum.ACTION_CHARACTER_ACTION_POINTS_USE, (short)(-template.ApCost));
            Fight.TryEndSequence(2, 0);
            return(true);
        }
Exemple #2
0
 public static void SendGameActionFightSpellCastMessage(IPacketReceiver client, ActionsEnum actionId, FightActor caster, FightActor target,
                                                        Cell cell, FightSpellCastCriticalEnum critical, bool silentCast,
                                                        Spell spell)
 {
     client.Send(new GameActionFightSpellCastMessage((short)actionId, caster.Id, silentCast, spell.Template.VerboseCast, target == null ? 0 : target.Id, silentCast ? (short)-1 : cell.Id, (sbyte)(critical),
                                                     (short)spell.Id, (sbyte)spell.CurrentLevel, new short[0]));
 }
Exemple #3
0
 public static void SendGameActionFightSpellCastMessage(IPacketReceiver client, ActionsEnum actionId, FightActor caster, FightActor target,
                                                        Cell cell, FightSpellCastCriticalEnum critical, bool silentCast,
                                                        short spellId, sbyte spellLevel)
 {
     client.Send(new GameActionFightSpellCastMessage((short)actionId, caster.Id, silentCast, false, target == null ? 0 : target.Id, cell.Id, (sbyte)(critical),
                                                     spellId, spellLevel, new short[0]));
 }
        public FightSpellCastCriticalEnum RollCriticalDice(SpellLevelRecord spell)
        {
            AsyncRandom asyncRandom           = new AsyncRandom();
            FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL;

            if (spell.CriticalHitProbability != 0u && asyncRandom.Next((int)this.CalculateCriticRate(spell.CriticalHitProbability)) == 0)
            {
                result = FightSpellCastCriticalEnum.CRITICAL_HIT;
            }
            return(result);
        }
        public FightSpellCastCriticalEnum RollCriticalDice(WeaponRecord weapon)
        {
            AsyncRandom asyncRandom           = new AsyncRandom();
            FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL;
            int num = (int)this.CalculateCriticRate(weapon.CriticalHitProbability) / 6;

            if (weapon.CriticalHitProbability != 0 && asyncRandom.Next(num) == 0)
            {
                result = FightSpellCastCriticalEnum.CRITICAL_HIT;
            }
            return(result);
        }
        public FightSpellCastCriticalEnum RollCriticalDice(WeaponTemplate weapon)
        {
            AsyncRandom asyncRandom = new AsyncRandom();

            FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL;

            if (weapon.CriticalHitProbability != 0u && asyncRandom.Next(100) < this.CalculateCriticRate((uint)weapon.CriticalHitProbability))
            {
                result = FightSpellCastCriticalEnum.CRITICAL_HIT;
            }

            return(result);
        }
        public List <ExtendedSpellEffect> GetWeaponEffects(FightSpellCastCriticalEnum critical)
        {
            List <ExtendedSpellEffect> results = new List <ExtendedSpellEffect>();

            foreach (var effect in RealEffects.ObjectEffects)
            {
                if (WeaponsDamagesEffects.Contains((EffectsEnum)effect.actionId))
                {
                    results.Add(TransformEffect(this, effect, Type, critical));
                }
            }
            return(results);
        }
Exemple #8
0
        void OnWeaponUsed(FightActor fighter, WeaponTemplate weapon, Cell cell, FightSpellCastCriticalEnum critical, bool silentCast)
        {
            if (critical == FightSpellCastCriticalEnum.CRITICAL_FAIL)
            {
                return;
            }

            if (m_weaponsUsed.Contains(fighter))
            {
                UpdateStatus(ChallengeStatusEnum.FAILED);
            }
            else
            {
                m_weaponsUsed.Add(fighter);
            }
        }
Exemple #9
0
        void OnWeaponUsed(FightActor fighter, WeaponTemplate weapon, Cell cell, FightSpellCastCriticalEnum critical, bool silentCast)
        {
            if (critical == FightSpellCastCriticalEnum.CRITICAL_FAIL)
            {
                return;
            }

            if (m_weaponsUsed.Any(x => x.First == fighter && x.Second == Fight.TimeLine.RoundNumber))
            {
                UpdateStatus(ChallengeStatusEnum.FAILED);
            }
            else
            {
                m_weaponsUsed.Add(new Pair <FightActor, int>(fighter, Fight.TimeLine.RoundNumber));
            }
        }
        private bool CloseCombat(SpellLevelRecord level, MapPoint castPoint, string rawZone, ushort weaponGId = 0)
        {
            SpellCastResultEnum canCast = this.CanCastSpell(level, this.CellId, castPoint.CellId);

            if (canCast != SpellCastResultEnum.Ok)
            {
                this.OnSpellCastFailed(canCast, level);
                return(false);
            }

            this.OnWeaponUsedEvt?.Invoke(this);

            this.Fight.SequencesManager.StartSequence(SequenceTypeEnum.SEQUENCE_WEAPON);

            FightSpellCastCriticalEnum fightSpellCastCriticalEnum = this.RollCriticalDice(level);
            bool criticalHit = fightSpellCastCriticalEnum == FightSpellCastCriticalEnum.CRITICAL_HIT;

            EffectInstance[] effects = (criticalHit ? level.CriticalEffects : level.Effects).ToArray();


            this.Fight.Send(new GameActionFightCloseCombatMessage((ushort)ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT,
                                                                  this.Id,
                                                                  false,
                                                                  false,
                                                                  0,
                                                                  castPoint.CellId,
                                                                  (sbyte)fightSpellCastCriticalEnum,
                                                                  weaponGId));

            SpellEffectsManager.Instance.HandleEffects(this,
                                                       effects,
                                                       level,
                                                       castPoint,
                                                       rawZone,
                                                       WeaponManager.WeaponTargetMask,
                                                       criticalHit);


            this.UseAp(level.ApCost);

            this.OnSpellCasted(level, this.CellId, fightSpellCastCriticalEnum);
            this.Fight.SequencesManager.EndSequence(SequenceTypeEnum.SEQUENCE_WEAPON);
            this.Fight.CheckDeads();
            this.Fight.CheckFightEnd();
            return(true);
        }
        public void HandleSpellEffects(SpellLevelRecord spell, short cellid, FightSpellCastCriticalEnum critical)
        {
            List <ExtendedSpellEffect> handledEffects = critical == FightSpellCastCriticalEnum.CRITICAL_HIT ? spell.CriticalEffects : spell.Effects;

            Dictionary <ExtendedSpellEffect, List <Fighter> > validatedEffectsDatas = new Dictionary <ExtendedSpellEffect, List <Fighter> >();


            SelectRandomEffect(handledEffects);
            foreach (var effect in handledEffects)
            {
                short[] cells  = ShapesProvider.Handle(effect.ZoneShape, cellid, CellId, effect.ZoneSize).ToArray();
                var     actors = GetAffectedActors(cells, effect.Targets);
                validatedEffectsDatas.Add(effect, actors);
            }
            foreach (var data in validatedEffectsDatas)
            {
                Fight.TryStartSequence(ContextualId, 1);
                SpellEffectsHandler.Handle(this, spell, data.Key, data.Value, cellid);
                Fight.TryEndSequence(1, 0);
            }
        }
Exemple #12
0
        public static void SendGameActionFightCloseCombatMessage(IPacketReceiver client, FightActor source, FightActor target, Cell cell, FightSpellCastCriticalEnum castCritical, bool silentCast, WeaponTemplate weapon)
        {
            ActionsEnum actionsEnum = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT;

            switch (castCritical)
            {
            case FightSpellCastCriticalEnum.CRITICAL_HIT:
                actionsEnum = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT_CRITICAL_HIT;
                break;

            case FightSpellCastCriticalEnum.CRITICAL_FAIL:
                actionsEnum = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT_CRITICAL_MISS;
                break;
            }
            client.Send(new GameActionFightCloseCombatMessage((ushort)actionsEnum, source.Id, (target == null) ? 0 : target.Id, cell.Id, (sbyte)castCritical, silentCast, (ushort)weapon.Id));
        }
        public override bool CastSpell(Spell spell, Cell cell)
        {
            bool result;

            if (!base.IsFighterTurn())
            {
                result = false;
            }
            else
            {
                if (spell.Id != 0 || this.Character.Inventory.TryGetItem(CharacterInventoryPositionEnum.ACCESSORY_POSITION_WEAPON) == null)
                {
                    result = base.CastSpell(spell, cell);
                }
                else
                {
                    BasePlayerItem basePlayerItem = this.Character.Inventory.TryGetItem(CharacterInventoryPositionEnum.ACCESSORY_POSITION_WEAPON);
                    WeaponTemplate weaponTemplate = basePlayerItem.Template as WeaponTemplate;
                    if (weaponTemplate == null || !this.CanUseWeapon(cell, weaponTemplate))
                    {
                        result = false;
                    }
                    else
                    {
                        base.Fight.StartSequence(SequenceTypeEnum.SEQUENCE_WEAPON);
                        AsyncRandom asyncRandom = new AsyncRandom();
                        FightSpellCastCriticalEnum fightSpellCastCriticalEnum = this.RollCriticalDice(weaponTemplate);
                        if (fightSpellCastCriticalEnum == FightSpellCastCriticalEnum.CRITICAL_FAIL)
                        {
                            this.OnWeaponUsed(weaponTemplate, cell, fightSpellCastCriticalEnum, false);
                            this.UseAP((short)weaponTemplate.ApCost);
                            base.Fight.EndSequence(SequenceTypeEnum.SEQUENCE_WEAPON, false);
                            base.PassTurn();
                            result = false;
                        }
                        else
                        {
                            if (fightSpellCastCriticalEnum == FightSpellCastCriticalEnum.CRITICAL_HIT)
                            {
                                this.m_criticalWeaponBonus = weaponTemplate.CriticalHitBonus;
                            }
                            this.m_isUsingWeapon = true;
                            System.Collections.Generic.IEnumerable <EffectDice> enumerable = (
                                from entry in basePlayerItem.Effects
                                where Singleton <EffectManager> .Instance.IsUnRandomableWeaponEffect(entry.EffectId)
                                select entry).OfType <EffectDice>();
                            System.Collections.Generic.List <SpellEffectHandler> list = new System.Collections.Generic.List <SpellEffectHandler>();
                            foreach (EffectDice current in enumerable)
                            {
                                if (current.Random <= 0 || asyncRandom.NextDouble() <= (double)current.Random / 100.0)
                                {
                                    SpellEffectHandler spellEffectHandler = Singleton <EffectManager> .Instance.GetSpellEffectHandler(current, this, spell, cell, fightSpellCastCriticalEnum == FightSpellCastCriticalEnum.CRITICAL_HIT);

                                    spellEffectHandler.EffectZone = new Zone(weaponTemplate.Type.ZoneShape, (byte)weaponTemplate.Type.ZoneSize, spellEffectHandler.CastPoint.OrientationTo(spellEffectHandler.TargetedPoint, true));
                                    spellEffectHandler.Targets    = (SpellTargetType.ALLY_1 | SpellTargetType.ALLY_2 | SpellTargetType.ALLY_SUMMONS | SpellTargetType.ALLY_STATIC_SUMMONS | SpellTargetType.ALLY_3 | SpellTargetType.ALLY_4 | SpellTargetType.ALLY_5 | SpellTargetType.ENNEMY_1 | SpellTargetType.ENNEMY_2 | SpellTargetType.ENNEMY_SUMMONS | SpellTargetType.ENNEMY_STATIC_SUMMONS | SpellTargetType.ENNEMY_3 | SpellTargetType.ENNEMY_4 | SpellTargetType.ENNEMY_5);
                                    list.Add(spellEffectHandler);
                                }
                            }
                            bool silentCast = list.Any((SpellEffectHandler entry) => entry.RequireSilentCast());
                            this.OnWeaponUsed(weaponTemplate, cell, fightSpellCastCriticalEnum, silentCast);
                            this.UseAP((short)weaponTemplate.ApCost);
                            foreach (SpellEffectHandler spellEffectHandler in list)
                            {
                                spellEffectHandler.Apply();
                            }
                            base.Fight.EndSequence(SequenceTypeEnum.SEQUENCE_WEAPON, false);
                            this.m_isUsingWeapon       = false;
                            this.m_criticalWeaponBonus = 0;
                            base.Fight.CheckFightEnd();
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
 public void HandleWeaponEffect(short cellid, List <ExtendedSpellEffect> handledEffects, FightSpellCastCriticalEnum critical)
 {
     foreach (var effect in handledEffects)
     {
         Fight.TryStartSequence(ContextualId, 1);
         short[] cells  = ShapesProvider.Handle(effect.ZoneShape, cellid, CellId, effect.ZoneSize).ToArray();
         var     actors = GetAffectedActors(cells, effect.Targets);
         SpellEffectsHandler.Handle(this, null, effect, actors, cellid);
         Fight.TryEndSequence(1, 0);
     }
     Fight.CheckFightEnd();
 }
        public virtual bool CastSpellOnCell(ushort spellid, short cellid, int targetId = 0)
        {
            SpellLevelRecord spellLevl = GetSpellLevel(spellid);

            if (!IsPlaying)
            {
                OnSpellCastFailed(CastFailedReason.NOT_PLAYING, spellLevl);
                return(false);
            }
            if (Fight.Ended)
            {
                OnSpellCastFailed(CastFailedReason.FIGHT_ENDED, spellLevl);
                return(false);
            }

            if (!ValidState(spellLevl))
            {
                OnSpellCastFailed(CastFailedReason.FORBIDDEN_STATE, spellLevl);
                return(false);
            }
            if (spellLevl.ApCost > FighterStats.Stats.ActionPoints)
            {
                OnSpellCastFailed(CastFailedReason.AP_COST, spellLevl);
                return(false);
            }
            if ((SpellIdEnum)spellid == SpellIdEnum.Punch)
            {
                UsingWeapon = true;
                bool result = UseWeapon(cellid);
                UsingWeapon = false;
                return(result);
            }
            if (targetId == 0)
            {
                var target = Fight.GetFighter(cellid);
                if (target != null)
                {
                    targetId = target.ContextualId;
                }
            }
            if (!SpellHistory.CanCast(spellLevl, targetId))
            {
                OnSpellCastFailed(CastFailedReason.CAST_LIMIT, spellLevl);
                return(false);
            }

            this.Fight.TryStartSequence(this.ContextualId, 1);
            FightSpellCastCriticalEnum critical = RollCriticalDice(spellLevl);

            short[] portals = new short[0];// WHAT THE F**K

            this.Fight.Send(new GameActionFightSpellCastMessage(0, ContextualId, targetId, cellid, (sbyte)critical, false, spellid, spellLevl.Grade, portals));
            this.SpellHistory.Add(spellLevl, targetId);

            #region EffectHandler

            if (CustomSpellEffectsProvider.Exist(spellid))
            {
                Fight.TryStartSequence(ContextualId, 1);
                CustomSpellEffectsProvider.Handle(spellid, spellLevl.Effects, this);
                Fight.TryEndSequence(1, 0);
            }
            else
            {
                HandleSpellEffects(spellLevl, cellid, critical);
            }
            #endregion

            FighterStats.Stats.ActionPoints -= spellLevl.ApCost;
            GameActionFightPointsVariation(ActionsEnum.ACTION_CHARACTER_ACTION_POINTS_USE, (short)-spellLevl.ApCost);
            if (CharacterRecord.GetCharacterRecordById(this.ContextualId) != null && CharacterRecord.GetCharacterRecordById(this.ContextualId).GodMod)
            {
                FighterStats.Stats.ActionPoints += spellLevl.ApCost;
                GameActionFightPointsVariation(ActionsEnum.ACTION_CHARACTER_ACTION_POINTS_WIN, (short)spellLevl.ApCost);
            }
            Fight.CheckFightEnd();

            if (Fight.Ended)
            {
                return(true);
            }
            RefreshStats();
            OnSpellCasted(spellLevl);
            this.Fight.TryEndSequence(1, 100);
            ApplyFighterEvent(FighterEventType.AFTER_USED_AP, spellLevl.ApCost);
            return(true);
        }
Exemple #16
0
 protected override void OnWeaponUsed(WeaponTemplate weapon, Cell cell, FightSpellCastCriticalEnum critical, bool silentCast)
 {
     m_weaponUses++;
     base.OnWeaponUsed(weapon, cell, critical, silentCast);
 }
Exemple #17
0
        public static void SendGameActionFightCloseCombatMessage(IPacketReceiver client, FightActor source, FightActor target, Cell cell, FightSpellCastCriticalEnum castCritical, bool silentCast, short weaponId)
        {
            var action = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT;

            switch (castCritical)
            {
            case FightSpellCastCriticalEnum.CRITICAL_FAIL:
                action = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT_CRITICAL_MISS;
                break;

            case FightSpellCastCriticalEnum.CRITICAL_HIT:
                action = ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT_CRITICAL_HIT;
                break;
            }

            client.Send(new GameActionFightCloseCombatMessage((short)action, source.Id, silentCast, true, target?.Id ?? 0, cell.Id, (sbyte)castCritical, weaponId));
        }
Exemple #18
0
 public static void SendGameActionFightCloseCombatMessage(IPacketReceiver client, FightActor source, FightActor target, Cell cell, FightSpellCastCriticalEnum castCritical, bool silentCast, WeaponTemplate weapon)
 {
     SendGameActionFightCloseCombatMessage(client, source, target, cell, castCritical, silentCast, (short)weapon.Id);
 }
Exemple #19
0
 void OnWeaponUsed(FightActor caster, WeaponTemplate weapon, Cell target, FightSpellCastCriticalEnum critical, bool silentCast)
 => UpdateStatus(ChallengeStatusEnum.FAILED);
        public static ExtendedSpellEffect TransformEffect(WeaponRecord record, ObjectEffectDice effect, ItemTypeEnum type, FightSpellCastCriticalEnum critical)
        {
            short dicenum  = (short)(critical == FightSpellCastCriticalEnum.CRITICAL_HIT ? effect.diceNum + record.CriticalHitBonus : effect.diceNum);
            short diceside = (short)(critical == FightSpellCastCriticalEnum.CRITICAL_HIT ? effect.diceSide + record.CriticalHitBonus : effect.diceSide);

            return(new ExtendedSpellEffect(new SpellEffectRecord(0, 0, (short)effect.actionId, GetWeaponRawZone(type), DefaultWeaponEffectsTargetMask, dicenum, diceside, 0, effect.diceConst, 0, 0)));
        }
Exemple #21
0
 public static void SendGameActionFightSpellCastMessage(IPacketReceiver client, ActionsEnum actionId, FightActor caster, FightActor target, Cell cell, FightSpellCastCriticalEnum critical, bool silentCast, short spellId, sbyte spellLevel)
 {
     client.Send(new GameActionFightSpellCastMessage((ushort)actionId, caster.Id, (target == null) ? 0 : target.Id, cell.Id, (sbyte)critical, silentCast, (ushort)spellId, spellLevel, Enumerable.Empty <short>()));
 }