static void UpdateBot(PlayerBot bot, string msg) { Chat.MessageLevel(bot.level, bot.ColoredName + "%S" + msg); Server.s.Log(bot.name + msg); BotsFile.UpdateBot(bot); }
public override bool Execute(PlayerBot bot, InstructionData data) { PlayerBot.Remove(bot); return(true); }
public override void Use(Player p, string message, CommandData data) { if (message.Length == 0) { Help(p); return; } bool preciseTP = message.CaselessStarts(precisePrefix); if (preciseTP) { message = message.Substring(precisePrefix.Length); } string[] args = message.SplitSpaces(); if (args.Length >= 3) { TeleportCoords(p, args, preciseTP); return; } Player target = null; PlayerBot bot = null; if (args.Length == 1) { target = PlayerInfo.FindMatches(p, args[0]); if (target == null) { return; } if (!CheckPlayer(p, target, data)) { return; } } else if (args[0].CaselessEq("bot")) { bot = Matcher.FindBots(p, args[1]); if (bot == null) { return; } } else { Help(p); return; } SavePreTeleportState(p); Level lvl = bot != null ? bot.level : target.level; if (p.level != lvl) { PlayerActions.ChangeMap(p, lvl.name); } if (target != null && target.Loading) { p.Message("Waiting for {0} %Sto spawn..", p.FormatNick(target)); target.BlockUntilLoad(10); } // Player wasn't able to join target map, so don't move if (p.level != lvl) { return; } Position pos = bot != null ? bot.Pos : target.Pos; Orientation rot = bot != null ? bot.Rot : target.Rot; p.BlockUntilLoad(10); //Wait for player to spawn in new map p.SendPos(Entities.SelfID, pos, rot); }
/// <summary> Performs a tick for this instruction. </summary> /// <returns> false if the bot should proceed to execute the /// next instruction in the same tick. </returns> public abstract bool Execute(PlayerBot bot, InstructionData data);
public override bool Execute(PlayerBot bot, InstructionData data) { bot.cur = 0; return(false); }
void RemoveBot(Player p, string botName, string extArgs) { if (botName.CaselessEq("all")) { //bot remove all[botname] griefer[extArgs] if (extArgs != null) { string ownerName = PlayerInfo.FindMatchesPreferOnline(p, extArgs); if (ownerName == null) { return; } if (PlayerBot.CanEditAny(p) || ownerName.CaselessEq(p.name)) { int removedCount = PlayerBot.RemoveBotsOwnedBy(p, ownerName, p.level, false); if (removedCount == 0) { p.Message("There are no bots owned by {0}%S in this level.", p.FormatNick(ownerName)); } else { p.Message("Removed {0} bot{1} belonging to {2}%S.", removedCount, removedCount > 1 ? "s" : "", p.FormatNick(ownerName)); BotsFile.Save(p.level); } } else { p.Message("&WYou cannot remove all bots belonging to {0}&W unless you are the owner of this map.", p.FormatNick(ownerName)); } return; } if (PlayerBot.CanEditAny(p)) { int removedCount = PlayerBot.RemoveLoadedBots(p.level, false); if (removedCount == 0) { p.Message("There are no bots in this level."); } else { p.Message("Removed {0} bot{1}.", removedCount, removedCount > 1 ? "s" : ""); BotsFile.Save(p.level); } } else { p.Message("&WYou cannot remove all bots unless you are the owner of this map."); } } else { PlayerBot bot = Matcher.FindBots(p, botName); if (bot == null) { return; } if (!bot.EditableBy(p, "remove")) { return; } PlayerBot.Remove(bot); p.Message("Removed bot {0}", bot.ColoredName); } }
public override void Use(Player p, string message) { if (message == "") { Help(p); return; } try { if (message.Split(' ').Length == 1) { PlayerBot pB = PlayerBot.Find(message); try { pB.Waypoints.Clear(); } catch { } pB.kill = false; pB.hunt = false; pB.AIName = ""; Player.SendMessage(p, pB.color + pB.name + Server.DefaultColor + "'s AI was turned off."); Server.s.Log(pB.name + "'s AI was turned off."); return; } else if (message.Split(' ').Length != 2) { Help(p); return; } PlayerBot Pb = PlayerBot.Find(message.Split(' ')[0]); if (Pb == null) { Player.SendMessage(p, "Could not find specified Bot"); return; } string foundPath = message.Split(' ')[1].ToLower(); if (foundPath == "hunt") { Pb.hunt = !Pb.hunt; try { Pb.Waypoints.Clear(); } catch { } Pb.AIName = ""; if (p != null) { Player.GlobalChatLevel(p, Pb.color + Pb.name + Server.DefaultColor + "'s hunt instinct: " + Pb.hunt, false); } Server.s.Log(Pb.name + "'s hunt instinct: " + Pb.hunt); return; } else if (foundPath == "kill") { if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { Player.SendMessage(p, "Only a " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + "+ may toggle killer instinct."); return; } Pb.kill = !Pb.kill; if (p != null) { Player.GlobalChatLevel(p, Pb.color + Pb.name + Server.DefaultColor + "'s kill instinct: " + Pb.kill, false); } Server.s.Log(Pb.name + "'s kill instinct: " + Pb.kill); return; } if (!File.Exists("bots/" + foundPath)) { Player.SendMessage(p, "Could not find specified AI."); return; } string[] foundWay = File.ReadAllLines("bots/" + foundPath); if (foundWay[0] != "#Version 2") { Player.SendMessage(p, "Invalid file version. Remake"); return; } PlayerBot.Pos newPos = new PlayerBot.Pos(); try { Pb.Waypoints.Clear(); Pb.currentPoint = 0; Pb.countdown = 0; Pb.movementSpeed = 12; } catch { } try { foreach (string s in foundWay) { if (s != "" && s[0] != '#') { bool skip = false; newPos.type = s.Split(' ')[0]; switch (s.Split(' ')[0].ToLower()) { case "walk": case "teleport": newPos.x = Convert.ToUInt16(s.Split(' ')[1]); newPos.y = Convert.ToUInt16(s.Split(' ')[2]); newPos.z = Convert.ToUInt16(s.Split(' ')[3]); newPos.rotx = Convert.ToByte(s.Split(' ')[4]); newPos.roty = Convert.ToByte(s.Split(' ')[5]); break; case "wait": case "speed": newPos.seconds = Convert.ToInt16(s.Split(' ')[1]); break; case "nod": case "spin": newPos.seconds = Convert.ToInt16(s.Split(' ')[1]); newPos.rotspeed = Convert.ToInt16(s.Split(' ')[2]); break; case "linkscript": newPos.newscript = s.Split(' ')[1]; break; case "reset": case "jump": case "remove": break; default: skip = true; break; } if (!skip) { Pb.Waypoints.Add(newPos); } } } } catch { Player.SendMessage(p, "AI file corrupt."); return; } Pb.AIName = foundPath; if (p != null) { Player.GlobalChatLevel(p, Pb.color + Pb.name + Server.DefaultColor + "'s AI is now set to " + foundPath, false); } Server.s.Log(Pb.name + "'s AI was set to " + foundPath); } catch { Player.SendMessage(p, "Error"); return; } }
/// <summary> /// Continue the game: have the player take his action. /// When the player stands or doubles, the dealer plays and the winner is determined. /// In each state of the game update the quality value of the action taken to reach this state. /// When "print" is true, the steps are written in the console. /// </summary> /// <param name="qualityTable"></param> /// <param name="randomGenerator"></param> /// <param name="print"></param> public void Start(QualityTable qualityTable, Random randomGenerator, bool print) { bool gameStatus = true; //is the player done? bool doublePossible = true; //is the player already hit? double rewardDouble = 1.0; //doubles when the player choose to DOUBLE! //sample the current state of the game. State currentState = qualityTable.GetState(this.PlayerBot, this.DealerBot); State newState; if (print) { Console.WriteLine("Game Started"); Console.WriteLine("Dealer card: " + DealerBot.DealerHand.Cards.First().Rank); Console.WriteLine("Player hand: " + PlayerBot.PlayerHand.Cards.First().Rank + " and " + PlayerBot.PlayerHand.Cards.Last().Rank); } //have the player play until he stands or doubles. while (gameStatus) { //player decide what action to take int action = -1; Random explorationPath = randomGenerator; if (explorationPath.NextDouble() < qualityTable.Epsilon) { action = explorationPath.Next(3); } else { action = currentState.ActionQuality.IndexOf(currentState.ActionQuality.Max()); } //sample current state currentState = qualityTable.GetState(this.PlayerBot, this.DealerBot); //perform action //stand! if (action == 0) { if (print) { Console.WriteLine("Player stands!"); } PlayerBot.Stand(); DealerBot.Play(this.Deck); gameStatus = false; } //hit! else if (action == 1) { if (print) { Console.WriteLine("Player hit!"); } doublePossible = false; PlayerBot.Hit(this.Deck); } //double! else if (action == 2 && doublePossible) { if (print) { Console.WriteLine("Player doubles!"); } PlayerBot.Hit(this.Deck); rewardDouble = 2.0; DealerBot.Play(this.Deck); gameStatus = false; } double stageReward; //update new state and take reward. newState = qualityTable.GetState(this.PlayerBot, this.DealerBot); //punish the player if he tries to double when not allowed. if (action == 2 && !doublePossible) { gameStatus = false; stageReward = -10; if (print) { Console.WriteLine("Player made an illegal move"); } } //multiply the reward when game is finished. else { if (!gameStatus) { rewardDouble *= 10.0; } stageReward = newState.Reward * rewardDouble; } //update q table qualityTable.UpdateQuality(currentState, newState, action, stageReward); currentState = newState; if (print && !gameStatus) { Console.WriteLine("Final Hands:"); Console.Write("Dealer: "); DealerBot.DealerHand.Cards.ForEach(o => Console.Write(o.Rank + " ")); Console.Write(System.Environment.NewLine + "Player: "); PlayerBot.PlayerHand.Cards.ForEach(o => Console.Write(o.Rank + " ")); Console.WriteLine(" "); if (currentState.Reward > 0) { Console.WriteLine("Player Wins!"); } if (currentState.Reward == 0) { Console.WriteLine("Tie!"); } if (currentState.Reward < 0) { Console.WriteLine("Player Loses!"); } } } }
public override void Use(Player p, string message, CommandData data) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); PlayerBot bot = Matcher.FindBots(p, args[0]); if (bot == null) { return; } if (!LevelInfo.Check(p, data.Rank, p.level, "change AI of bots in this level")) { return; } if (!bot.EditableBy(p, "change the AI of")) { return; } if (args.Length == 1) { bot.Instructions.Clear(); bot.kill = false; bot.hunt = false; bot.AIName = null; UpdateBot(p, bot, "'s AI was turned off."); return; } else if (args.Length != 2) { Help(p); return; } string ai = args[1].ToLower(); if (ai.CaselessEq("hunt")) { bot.hunt = !bot.hunt; bot.Instructions.Clear(); bot.AIName = null; UpdateBot(p, bot, "'s hunt instinct: " + bot.hunt); return; } else if (ai.CaselessEq("kill")) { if (!CheckExtraPerm(p, data, 1)) { return; } bot.kill = !bot.kill; UpdateBot(p, bot, "'s kill instinct: " + bot.kill); return; } if (!ScriptFile.Parse(p, bot, ai)) { return; } UpdateBot(p, bot, "'s AI was set to " + ai); }
static void UpdateBot(Player p, PlayerBot bot, string msg) { p.Message(bot.ColoredName + "%S" + msg); Logger.Log(LogType.UserActivity, bot.name + msg); BotsFile.Save(p.level); }
protected virtual void SetBotData(Player p, PlayerBot bot, string args) { }
internal static void UpdateEntityPositions(SchedulerTask task) { Entities.GlobalUpdate(); PlayerBot.GlobalUpdatePosition(); task.Delay = TimeSpan.FromMilliseconds(Server.Config.PositionUpdateInterval); }