public BotGame CreateBot(bool startBot) { Log("Creating new bot"); string username = "******" + randomGenerator.Next(); string password = randomGenerator.Next().ToString(); lock (factoryGame) factoryGame.DoSayChat(".account create " + username + " " + password); uint behaviorRandomIndex = (uint)randomGenerator.Next(100); uint behaviorCurrentIndex = 0; BotBehaviorSettings botBehavior = botBehaviors.Values.First(); foreach (var behavior in botBehaviors.Values) { if (behaviorRandomIndex < behaviorCurrentIndex + behavior.Probability) { botBehavior = behavior; break; } behaviorCurrentIndex += behavior.Probability; } BotGame game = new BotGame(Settings.Default.Hostname, Settings.Default.Port, username, password, Settings.Default.RealmID, 0, botBehavior); if (startBot) { game.Start(); } botInfos.Add(new BotInfo(username, password, botBehavior.Name)); return(game); }
public BotGame(string hostname, int port, string username, string password, int realmId, int character, BotBehaviorSettings behavior) : base(hostname, port, username, password, realmId, character) { this.Behavior = behavior; #region AutoResurrect if (Behavior.AutoResurrect) { // Resurrect if bot reaches 0 hp AddTrigger(new Trigger(new[] { new UpdateFieldTriggerAction((int)UnitField.UNIT_FIELD_HEALTH, 0) }, () => { CancelActionsByFlag(ActionFlag.Movement); Resurrect(); })); // Resurrect sequence AddTrigger(new Trigger(new TriggerAction[] { new UpdateFieldTriggerAction((int)PlayerField.PLAYER_FLAGS, (uint)PlayerFlags.PLAYER_FLAGS_GHOST, () => { OutPacket corpseQuery = new OutPacket(WorldCommand.MSG_CORPSE_QUERY); SendPacket(corpseQuery); }), new OpcodeTriggerAction(WorldCommand.MSG_CORPSE_QUERY, packet => { var inPacket = packet as InPacket; if (inPacket == null) { return(false); } bool found = inPacket.ReadByte() != 0; if (found) { var mapId = inPacket.ReadInt32(); var corpsePosition = new Position(inPacket.ReadSingle(), inPacket.ReadSingle(), inPacket.ReadSingle(), 0.0f, inPacket.ReadInt32()); Player.CorpsePosition = corpsePosition.GetPosition(); if (mapId == corpsePosition.MapID) { MoveTo(corpsePosition); return(true); } } return(false); }), new CustomTriggerAction(TriggerActionType.DestinationReached, (inputs) => { if (Player.IsGhost && (Player.CorpsePosition - Player).Length <= 39f) { if (DateTime.Now > CorpseReclaim) { return(true); } else { ScheduleAction(() => HandleTriggerInput(TriggerActionType.DestinationReached, inputs), CorpseReclaim.AddSeconds(1)); } } return(false); }, () => { OutPacket reclaimCorpse = new OutPacket(WorldCommand.CMSG_RECLAIM_CORPSE); reclaimCorpse.Write(Player.GUID); SendPacket(reclaimCorpse); }) }, null)); } #endregion }
public BotGame(string hostname, int port, string username, string password, int realmId, int character, BotBehaviorSettings behavior) : base(hostname, port, username, password, realmId, character) { this.Behavior = behavior; #region AutoResurrect if (Behavior.AutoResurrect) { // Resurrect if bot reaches 0 hp AddTrigger(new Trigger(new[] { new UpdateFieldTriggerAction((int)UnitField.UNIT_FIELD_HEALTH, 0) }, () => { CancelActionsByFlag(ActionFlag.Movement); Resurrect(); })); // Resurrect sequence AddTrigger(new Trigger(new TriggerAction[] { new UpdateFieldTriggerAction((int)PlayerField.PLAYER_FLAGS, (uint)PlayerFlags.PLAYER_FLAGS_GHOST, () => { OutPacket corpseQuery = new OutPacket(WorldCommand.MSG_CORPSE_QUERY); SendPacket(corpseQuery); }), new OpcodeTriggerAction(WorldCommand.MSG_CORPSE_QUERY, packet => { var inPacket = packet as InPacket; if (inPacket == null) return false; bool found = inPacket.ReadByte() != 0; if (found) { var mapId = inPacket.ReadInt32(); var corpsePosition = new Position(inPacket.ReadSingle(), inPacket.ReadSingle(), inPacket.ReadSingle(), 0.0f, inPacket.ReadInt32()); Player.CorpsePosition = corpsePosition.GetPosition(); if (mapId == corpsePosition.MapID) { MoveTo(corpsePosition); return true; } } return false; }), new CustomTriggerAction(TriggerActionType.DestinationReached, (inputs) => { if (Player.IsGhost && (Player.CorpsePosition - Player).Length <= 39f) { if (DateTime.Now > CorpseReclaim) return true; else ScheduleAction(() => HandleTriggerInput(TriggerActionType.DestinationReached, inputs), CorpseReclaim.AddSeconds(1)); } return false; },() => { OutPacket reclaimCorpse = new OutPacket(WorldCommand.CMSG_RECLAIM_CORPSE); reclaimCorpse.Write(Player.GUID); SendPacket(reclaimCorpse); }) }, null)); } #endregion }