private void CastSpell(IFighter fighter, IASpell spell) { Logger.Default.Log($"Casting spell {spell.Name} at {fighter.CellId}"); if (spell.SpellId == 0) { _account.Network.SendToServer(new GameActionFightCastRequestMessage((ushort)spell.SpellId, (short)fighter.CellId)); } else { _account.Network.SendToServer(new GameActionFightCastOnTargetRequestMessage((ushort)spell.SpellId, fighter.Id)); } }
public virtual void DeepCopyIn( IASpell item, IASpellGetter rhs, ErrorMaskBuilder?errorMask, TranslationCrystal?copyMask, bool deepCopy) { base.DeepCopyIn( (ISkyrimMajorRecord)item, (ISkyrimMajorRecordGetter)rhs, errorMask, copyMask, deepCopy: deepCopy); }
private void ExecuteSpell() { Logger.Default.Log($"Vie du bot: {_account.Character.LifePercentage}"); if (_spells == null) { return; } var monster = _account.Character.Fight.NearestMonster(); //foreach (var spell in _spells) //{ var spell = _spells[0]; _currentSpell = spell; var fighter = (IFighter)monster; if (spell.Target == SpellTarget.Self) { fighter = _account.Character.Fight.Fighter; } var useSpell = _account.Character.Fight.CanUseSpell(spell.SpellId, fighter); var nameSpell = D2OParsing.GetSpellName(spell.SpellId); if (_totalSpellLauch <= spell.Relaunchs) { Logger.Default.Log($"Attaque {monster.Name}"); switch (useSpell) { case -1: _account.Character.Fight.EndTurn(); break; case 0: Logger.Default.Log($"Lancement de {nameSpell}"); _spellEvent = new SpellCast(_account, spell.SpellId, fighter.CellId); _spellEvent.SpellCasted += OnSpellCasted; _spellEvent.PerformCast(); break; default: Logger.Default.Log($"Déplacement en {useSpell}"); var movement = _account.Character.Fight.MoveToCell(useSpell); movement.MovementFinished += (sender, e) => { if (e.Sucess) { Logger.Default.Log($"Lancement de {nameSpell}"); _spellEvent = new SpellCast(_account, spell.SpellId, fighter.CellId); _spellEvent.SpellCasted += OnSpellCasted; _spellEvent.PerformCast(); } else { Logger.Default.Log( $"Erreur lors du lancement du spell {spell.SpellId} sur la cell {fighter.CellId}", LogMessageType.Public); } }; movement.PerformMovement(); break; } } else { _totalSpellLauch = 0; _account.Character.Fight.EndTurn(); } }
public void RemapLinks(IASpell obj, IReadOnlyDictionary <FormKey, FormKey> mapping) { base.RemapLinks(obj, mapping); }
private MovementEnum MoveToHit(IFighter fighter, IASpell spell, bool handToHand = false) { if (Moving) { return(MovementEnum.AlreadyInMove); } if (Fighter.MovementPoints <= 0) //not Enough movement points. { return(MovementEnum.NoMovementPoints); } //Bot has to move somewhere. var moveCell = -1; var distance = -1; // We gonna be looking for the smaller distance to go in order to be able to cast this _currentSkill if (handToHand) { foreach (var destCell in _account.Character.Fight.GetReachableCells()) // gathering where the bot can go. { if (_account.Character.Fight.IsHandToHand(destCell)) {//if we gonna be handtohand to the nearestmob then we can break the loop moveCell = destCell; MapPoint characterPoint = new MapPoint(destCell); distance = characterPoint.DistanceToCell(new MapPoint(fighter.CellId)); break; } } } else { foreach (var destCell in _account.Character.Fight.GetReachableCells()) // gathering where the bot can go. Not pathFinding tho. { if (_account.Character.Fight.CanLaunchSpellOn(spell.SpellId, destCell, fighter.CellId, true) != SpellInabilityReason.None) { continue; //this specific destCell wont let it use this specific skill } MapPoint characterPoint = new MapPoint(destCell); int tempDistance = characterPoint.DistanceToCell(new MapPoint(fighter.CellId)); if (tempDistance <= distance && distance != -1) { continue; } distance = tempDistance; moveCell = destCell; } } if (moveCell == -1) // even moving wont be able to hit the target { return(MovementEnum.NotEnoughMovement); } ICellMovement movement = _account.Character.Fight.MoveToCell(moveCell); if (movement != null) { //movement.MovementFinished += (x,e) => //{ // Moving = false; // if (e.Sucess) // If success then we send a signal to continue with execution. If it fails let it return null; // { // Logger.Default.Log($"{e.Distance} Mps used Total[{Fighter.MovementPoints}]",LogMessageType.FightLog); // Fighter.MovementPoints -= (short)(e.Distance+1); // movementAutoReset.Set(); // }else // Logger.Default.Log($"Movement Performed but failed.", LogMessageType.FightLog); // return; //}; //Moving = true; movement.MovementFinished += Movement_MovementFinished; movement.PerformMovement(); return(MovementEnum.Success); } throw new Exception("Movement cannot be null"); }
private void ExecuteSpell(IASpell spell, IFighter target) { Logger.Default.Log($"ExecuteSpell {spell.Name}"); try { if (spell.HandToHand && !_account.Character.Fight.IsHandToHand()) { if (Fighter.MovementPoints > 0 && MoveToHit(target, spell, true) == MovementEnum.Success) { if (MovementAutoReset.WaitOne(TimeOut)) // Waiting some time for MovementAnswer finished. If true then call recursively { Logger.Default.Log($"Movement succeeded and Bot is HandToHand to cast {spell.Name}.", LogMessageType.FightLog); ExecuteSpell(spell, target);//in theory it should be HandToHand }// if movement fails let it return let it returns; else { Logger.Default.Log($"Movement Failed. Bot couldn't not get HandToHand to cast {spell.Name}.", LogMessageType.FightLog); } } else { Logger.Default.Log($"Movement cannot be performed to cast {spell.Name}.", LogMessageType.FightLog); } } else { if (target == null) { return; } SpellInabilityReason reason = _account.Character.Fight.CanLaunchSpellOn(spell.SpellId, Fighter.CellId, target.CellId); switch (reason) { case SpellInabilityReason.ActionPoints: case SpellInabilityReason.RequiredState: case SpellInabilityReason.TooManyLaunch: case SpellInabilityReason.TooManyLaunchOnCell: case SpellInabilityReason.Unknown: case SpellInabilityReason.UnknownSpell: // any of those conditions we can't do anything other then going to the next spell. so, let it return; break; case SpellInabilityReason.None: CastSpell(target, spell); if (_account.Character.Fight.SpellResetEvent.WaitOne(TimeOut)) { Logger.Default.Log($"Successfully launched {spell.Name}", LogMessageType.FightLog); } else { Logger.Default.Log($"Could not cast {spell.Name} at {target.CellId} ", LogMessageType.FightLog); } break; default: if (Fighter.MovementPoints > 0 && MoveToHit(target, spell, false) == MovementEnum.Success) { if (MovementAutoReset.WaitOne(TimeOut)) // If movement was a success then we call recursively { ExecuteSpell(spell, target); } } break; } } if (!FighterDiedAutoReset.WaitOne(Delay)) { return; // Wait to see if mob died. If true then we Task.Await } Task.Delay(Delay / 2).Wait(); return; } catch (Exception) { } }