/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = Int32.MaxValue; foreach (Arena.FlagState fs in _arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; } if (_arena._name.ToLower().Substring(0, 3) == "ovd") { _IsOvD = true; _ovd = new OvD(_arena); } return(true); }
/// <summary> /// Initializes events for the event object /// </summary> static public void eventInit(IEventObject obj, bool bParseEvents) { //Initialize variables obj.events = new EventHandlers(obj); obj._sync = new object(); if (bParseEvents) { //Obtain the group type Type type = obj.GetType(); //Initialize all script events foreach (MethodInfo method in type.GetMethods()) { //Look at it's attributes.. foreach (Attribute attr in method.GetCustomAttributes(true)) { //.. until we find an event handler attribute Scripts.Event ehdlr = attr as Scripts.Event; if (ehdlr == null) { continue; } //Register the event with the group eventobject obj.events[ehdlr.eventname] += new CEventHandler(obj, method.Name); } } } }
private CfgInfo _config; //The zone config /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; return(true); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = Int32.MaxValue; //Teams teamOne = new arenaTeam(_arena.getTeamByID(0), 403); teamTwo = new arenaTeam(_arena.getTeamByID(1), 422); foreach (Arena.FlagState fs in _arena._flags.Values) { if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; if (_minPlayers == Int32.MaxValue) { //No flags? Run blank games _minPlayers = 1; } } return(true); }
private void SelectEvent(IEventObject eventObject) { selectedEvent = eventObject; if (selectedEvent != null) { var treeNode = FindEventTreeNode(tvMaps.Nodes, eventObject); if (treeNode != null) { foreach (TreeNode node in treeNode.Parent.Parent.Nodes) { if (!node.Nodes.Contains(treeNode)) { node.Collapse(); } } tvMaps.SelectedNode = treeNode; } eventInformationToolStripMenuItem.Enabled = true; tsslStatus.Text = $"Selected {eventObject.GetType().Name} event at (X:{eventObject.X - ((eventObject is NPC) ? 4 : 0)}, Y:{eventObject.Y - ((eventObject is NPC) ? 4 : 0)})"; } else { eventInformationToolStripMenuItem.Enabled = false; tsslStatus.Text = "No event selected"; } pbMap.Invalidate(); pbBlocks.Invalidate(); }
////////////////////////////////////////////////// // Game Functions ////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { arena = invoker as Arena; CFG = arena._server._zoneConfig; minPlayers = 2; victoryHoldTime = CFG.flag.victoryHoldTime; preGamePeriod = CFG.flag.startDelay; killStreaks = new Dictionary <string, PlayerStreak>(); explosives = new Dictionary <string, int>(); for (int i = 0; i < explosiveList.Length; i++) { explosives.Add(explosiveList[i], explosiveAliveTimes[i]); } foreach (Arena.FlagState fs in arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < minPlayers) { minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += OnFlagChange; } gameState = GameState.Init; return(true); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; caverns = new LowerLevel(); _minPlayers = Int32.MaxValue; foreach (Arena.FlagState fs in _arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; } if (_minPlayers == Int32.MaxValue) { //No flags? Run blank games _minPlayers = 1; } return(true); }
private bool _team2Upgrade; //True if team 2 requires stronger bots /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = 2; //We want at least two players to start a game _hqVehId = 1; //Our HQ ID _towerVehId = 1; //Our tower ID _inhibVehId = 1; //Our inhibitor ID _team1Upgrade = false; //Default to no upgraded bots _team2Upgrade = false; _team1MinionX = 1; //Set where bots will spawn (pixels) _team1MinionY = 1; _team2MinionX = 1; _team2MinionY = 1; _team1 = "Titan"; _team2 = "Collective"; _victoryTeam = null; return(true); }
public bool init(IEventObject invoker) { //Populate our variables _Arena = invoker as Arena; _CFG = _Arena._server._zoneConfig; _Settings = new Settings(); _KOTH = new KOTH(_Arena, _Settings); _CTF = new CTF(_Arena, _Settings); _TDM = new TDM(_Arena, _Settings); _Gladiator = new Gladiator(_Arena, _Settings); _GameType = GameTypes.TDM; foreach (string type in gametypes) { Settings.AllowedGameTypes.Add((GameTypes)_Settings.GetType(type)); } //Put here so allowed game types aren't doubled in the vote system _VoteSystem = new VoteSystem(); _gameCount = 0; return(true); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = 2; _supplyBags = new List <Vehicle>(); return(true); }
private void EnsureEventVisible(IEventObject eventObject) { var zoom = (enableZoomToolStripMenuItem.Checked ? 2 : 1); var viewWidthEvents = (spnlMap.ClientSize.Width / (16 * zoom)); var viewHeightEvents = (spnlMap.ClientSize.Height / (16 * zoom)); spnlMap.HorizontalScroll.Value = Math.Min(spnlMap.HorizontalScroll.Maximum, (spnlMap.ClientSize.Width * (eventObject.X / viewWidthEvents))); spnlMap.VerticalScroll.Value = Math.Min(spnlMap.VerticalScroll.Maximum, (spnlMap.ClientSize.Height * (eventObject.Y / viewHeightEvents))); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _bot = invoker as Bot; _rand = new Random(); //Equip and fix up our bot! :) _bot._weapon.equip(AssetManager.Manager.getItemByID(_bot._type.InventoryItems[0])); //Construct our weapons list _weapons = new List <Assets.ItemInfo>(); Assets.ItemInfo item; foreach (int id in _bot._type.InventoryItems) { item = AssetManager.Manager.getItemByID(id); if (item != null) { _weapons.Add(item); } } if (_bot._type.Description.Length >= 4 && _bot._type.Description.Substring(0, 4).ToLower().Equals("bot=")) { string[] botparams; botparams = _bot._type.Description.Substring(4, _bot._type.Description.Length - 4).Split(','); foreach (string botparam in botparams) { if (!botparam.Contains(':')) { continue; } string paramname = botparam.Split(':').ElementAt(0).ToLower(); string paramvalue = botparam.Split(':').ElementAt(1).ToLower(); switch (paramname) { case "radius": _stalkRadius = Convert.ToInt32(paramvalue); break; case "distance": _optimalDistance = Convert.ToInt32(paramvalue); break; case "tolerance": _optimalDistanceTolerance = Convert.ToInt32(paramvalue); break; case "strafe": _distanceTolerance = Convert.ToInt32(paramvalue); break; } } } return(true); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = _config.king.minimumPlayers; _playerCrownStatus = new Dictionary <Player, PlayerCrownStatus>(); _crownTeams = new List <Team>(); return(true); }
private int _minPlayers; //The minimum amount of players /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _rand = new Random(); _minPlayers = 2; team1 = _arena.getTeamByName(_config.teams[0].name); team2 = _arena.getTeamByName(_config.teams[1].name); queue = new Dictionary <Player, int>(); inPlayers = new Dictionary <Player, bool>(); return(true); }
/// <summary> /// Instances all available scripts for an invoker /// </summary> static public List <IScript> instanceScripts(IEventObject invoker, string invokerType) { //Get our scripts List <Type> scripts; if (!_invokerScripts.TryGetValue(invokerType, out scripts)) { //Invalid bot type! throw new ArgumentException("Invalid invoker type for instancing: " + invokerType); } //Instance them all! int instanced = 0; List <IScript> iscripts = new List <IScript>(); foreach (Type script in scripts) { IScript iscript = (IScript)Activator.CreateInstance(script); //Now allow it to initialize bool success = iscript.init(invoker); if (!success) { continue; } instanced++; //Look though all the methods present foreach (MethodInfo method in script.GetMethods()) { //Look at it's attributes.. foreach (Attribute attr in method.GetCustomAttributes(true)) { //.. until we find event attribute Event ehdlr = attr as Event; if (ehdlr != null) { //Register the event invoker.events[ehdlr.eventname] += new CEventHandler(iscript, method.Name); } } } //Add it to our list iscripts.Add(iscript); } Log.write(TLog.Inane, "Instanced " + instanced + " '" + invokerType + "' scripts."); return(iscripts); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = Int32.MaxValue; //The flag's ID that corresponds to whichever team. teamOne.flagId = 102; teamOne.flagId = 101; //Assign each team's portal (goal box) teamOne.portalId = 133; teamTwo.portalId = 134; //Assign the teams teamOne.arenaTeam = _arena.getTeamByID(0); teamTwo.arenaTeam = _arena.getTeamByID(1); //Assign each team names teamOne.arenaTeam._name = _config.teams[0].name; teamTwo.arenaTeam._name = _config.teams[1].name; //Assign each team's flag teamOne.flag = _arena._flags.Values.Where(f => f.flag.GeneralData.Id == 102).First(); teamTwo.flag = _arena._flags.Values.Where(f => f.flag.GeneralData.Id == 101).First(); foreach (Arena.FlagState fs in _arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; } if (_minPlayers == Int32.MaxValue) { //No flags? Run blank games _minPlayers = 1; } return(true); }
private int _lastHQReward; //The tick at which we last checked for HQ rewards /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; //Headquarters stuff! _hqlevels = new int[] { 500, 1000, 2500, 5000, 10000, 15000, 20000, 25000, 30000, 35000 }; _hqVehId = 463; _baseXPReward = 25; _baseCashReward = 150; _basePointReward = 10; _rewardInterval = 90 * 1000; // 90 seconds _hqs = new Headquarters(_hqlevels); _hqs.LevelModify += onHQLevelModify; return(true); }
private bool _bChasing; //Are we chasing the player back into optimal range? /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _bot = invoker as Bot; _rand = new Random(); //Equip and fix up our bot! :) _bot._weapon.equip(AssetManager.Manager.getItemByID(_bot._type.InventoryItems[0])); //Maybe they want to assign custom settings? if (_bot._type.Description.Length >= 4 && _bot._type.Description.Substring(0, 4).ToLower().Equals("bot=")) { string[] botparams; botparams = _bot._type.Description.Substring(4, _bot._type.Description.Length - 4).Split(','); foreach (string botparam in botparams) { if (!botparam.Contains(':')) { continue; } string paramname = botparam.Split(':').ElementAt(0).ToLower(); string paramvalue = botparam.Split(':').ElementAt(1).ToLower(); switch (paramname) { case "radius": _stalkRadius = Convert.ToInt32(paramvalue); break; case "distance": _optimalDistance = Convert.ToInt32(paramvalue); break; case "tolerance": _optimalDistanceTolerance = Convert.ToInt32(paramvalue); break; case "strafe": _distanceTolerance = Convert.ToInt32(paramvalue); break; } } } return(true); }
private TreeNode FindEventTreeNode(TreeNodeCollection nodes, IEventObject eventObject) { TreeNode foundNode = null; foreach (TreeNode node in nodes) { if ((node.Tag is System.Runtime.CompilerServices.ITuple tuple) && (tuple.Length == 2) && (tuple[0] is Map) && (tuple[1] == eventObject)) { return(node); } foundNode = FindEventTreeNode(node.Nodes, eventObject); if (foundNode != null) { break; } } return(foundNode); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _arena.playtimeTickerIdx = 3; //Sets the global ticker index _minPlayers = _config.deathMatch.minimumPlayers; //For flag games foreach (Arena.FlagState fs in _arena._flags.Values) { //Register our flag change events fs.TeamChange += onFlagChange; } _savedPlayerStats = new Dictionary <String, PlayerStats>(); return(true); }
public MainForm() { InitializeComponent(); foreach (var control in Controls) { (control as Control).Font = SystemFonts.MessageBoxFont; } Text = Application.ProductName; tsslStatus.Text = "Ready"; gameHandler = null; gameDrawing = null; selectedMap = null; selectedEvent = null; blocksWidth = 4; gridPen = new Pen(Color.FromArgb(128, Color.Gray)); UIHelpers.AddFontFromResource("G15Map.Data.PixelFont.smallest_pixel-7.ttf"); spnlMap.Resize += (s, e) => { spnlMap.Refresh(); }; spnlBlocks.Resize += (s, e) => { spnlBlocks.Refresh(); }; pbBlocks.MouseDown += (s, e) => { pbBlocks.Parent?.Focus(); }; showEventOverlayToolStripMenuItem.CheckedChanged += (s, e) => { pbMap.Invalidate(); pbBlocks.Invalidate(); }; showGridOverlayToolStripMenuItem.CheckedChanged += (s, e) => { pbMap.Invalidate(); pbBlocks.Invalidate(); }; showDebugWarpsToolStripMenuItem.CheckedChanged += (s, e) => { pbMap.Invalidate(); pbBlocks.Invalidate(); }; useNighttimePalettesToolStripMenuItem.CheckedChanged += (s, e) => { pbMap.Invalidate(); pbBlocks.Invalidate(); }; enableZoomToolStripMenuItem.CheckedChanged += (s, e) => { LoadMap(selectedMap); pbMap.Invalidate(); pbBlocks.Invalidate(); }; #if DEBUG if (Environment.MachineName == "RIN-CORE") { LoadROM(@"D:\Games\Game Boy & Advance\Pokemon GS Spaceworld 1997 Demos\Pokémon Gold - Spaceworld 1997 Demo (Debug) (Header Fixed).sgb"); //tilesetViewerToolStripMenuItem_Click(tilesetViewerToolStripMenuItem, EventArgs.Empty); //tvMaps.SelectedNode = tvMaps.Nodes[0].Nodes[3]; } #endif }
private bool _gameWon = false; //Is this a possible win? /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _arena.playtimeTickerIdx = 3; //Sets the global index for our ticker _minPlayers = _config.deathMatch.minimumPlayers; foreach (Arena.FlagState fs in _arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; } return(true); }
public event Action EventOff; //Turns off all events when *event off is called #endregion #region Game Functions /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _arena.playtimeTickerIdx = 3; //Sets the global index for our ticker _gamePlay = new GamePlay(_arena); _gamePlay.Initiate(); _minPlayers = _config.deathMatch.minimumPlayers; _eventVoting = new Dictionary <string, List <int> >(); _votingTime = _gamePlay.VotingTime; //Allow voting here? if (!_arena._bIsPublic) { _gamePlay.Voting = false; } return(true); }
/////////////////////////////////////////////////// // Game Functions /////////////////////////////////////////////////// public bool init(IEventObject invoker) { arena = invoker as Arena; CFG = arena._server._zoneConfig; arena.playtimeTickerIdx = 3; //Sets the global ticker index used for changing the timer MinPlayers = CFG.deathMatch.minimumPlayers; MinDeaths = 3; //Change this if we want to run a higher death count DefaultMinDeaths = MinDeaths; VictoryHoldTime = CFG.flag.victoryHoldTime; PreGamePeriod = CFG.deathMatch.startDelay; DeathmatchTimer = CFG.deathMatch.timer; CurrentPlayerStats = new Dictionary <string, PlayerStats>(); foreach (Arena.FlagState fs in arena._flags.Values) { //Register our flag games fs.TeamChange += OnFlagChange; } GameStates = GameState.Init; LeagueStates = LeagueState.None; return(true); }
/// <summary> /// Calls a singlecast event, returning a value /// </summary> public static object callsync(IEventObject obj, string name, bool bSync, params object[] args) { //Play safe? if (bSync) { using (DdMonitor.Lock(obj._sync)) { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) //No? No need to worry return null; //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) ret = eh.handler(eh.that, args); else //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); //Got our loot, return with it return ret; } } return null; } } else { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) //No? No need to worry return null; //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) ret = eh.handler(eh.that, args); else //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); //Got our loot, return with it return ret; } } return null; } }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = Int32.MaxValue; _arena.playtimeTickerIdx = 1; //The game timer //Headquarters stuff! _hqlevels = new int[] { 500, 1000, 2500, 5000, 10000, 15000, 20000, 25000, 30000, 35000 }; _hqVehId = 463; _baseXPReward = 25; _baseCashReward = 150; _basePointReward = 10; _rewardInterval = 90 * 1000; // 90 seconds _hqs = new Headquarters(_hqlevels); _hqs.LevelModify += onHQLevelModify; //oState //_oStates = new Dictionary<Player, Helper.oState>(); foreach (Arena.FlagState fs in _arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < _minPlayers) { _minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += onFlagChange; } if (_minPlayers == Int32.MaxValue) { //No flags? Run blank games _minPlayers = 1; } _minPlayers = 6; if (_minPlayers > 0) { _playerCrownStatus = new Dictionary <Player, PlayerCrownStatus>(); _crownTeams = new List <Team>(); } using (StreamReader sr = new StreamReader("./assets/FantasyBots.txt")) { String bots = sr.ReadToEnd(); var values = bots.Split(','); int i = 0, j = 0; while (i < (values.Count() - 1)) { if (values[i] == "!") { i++; } _spawns.Add(new fantasyBot(j)); _spawns[j].ID = j; //Basics _spawns[j].vehID = Int32.Parse(values[i++]); _spawns[j].spawnID = Int32.Parse(values[i++]); _spawns[j].count = Int32.Parse(values[i++]); _spawns[j].max = Int32.Parse(values[i++]); _spawns[j].multiple = Int32.Parse(values[i++]); _spawns[j].ticksBetweenSpawn = Int32.Parse(values[i++]); //Bools _spawns[j].atkBots = Boolean.Parse(values[i++]); _spawns[j].atkVeh = Boolean.Parse(values[i++]); _spawns[j].atkPlayer = Boolean.Parse(values[i++]); _spawns[j].atkCloak = Boolean.Parse(values[i++]); _spawns[j].patrol = Boolean.Parse(values[i++]); //Distances _spawns[j].defenseRadius = Int32.Parse(values[i++]); _spawns[j].distanceFromHome = Int32.Parse(values[i++]); _spawns[j].patrolRadius = Int32.Parse(values[i++]); _spawns[j].lockInTime = Int32.Parse(values[i++]); _spawns[j].attackRadius = Int32.Parse(values[i++]); int totalWeapons = Int32.Parse(values[i]); i++; int k = 0; Log.write("Adding bot weapons -- total:" + totalWeapons); while (k < totalWeapons) { _spawns[j]._weapons.Add(new fantasyBot.BotWeapon(k)); Log.write("Added bot weapon - " + k); _spawns[j]._weapons[k].weaponID = Int32.Parse(values[i++]); Log.write("Added bot weapon - " + _spawns[j]._weapons[k].weaponID); _spawns[j]._weapons[k].allChance = Int32.Parse(values[i++]); _spawns[j]._weapons[k].shortChance = Int32.Parse(values[i++]); _spawns[j]._weapons[k].midChance = Int32.Parse(values[i++]); _spawns[j]._weapons[k].longChance = Int32.Parse(values[i++]); _spawns[j]._weapons[k].preferredRange = Int32.Parse(values[i++]); k++; } _spawns[j].shortRange = Int32.Parse(values[i++]); _spawns[j].mediumRange = Int32.Parse(values[i++]); _spawns[j].longRange = Int32.Parse(values[i++]); //Waypoint Settings int totalWaypoints = Int32.Parse(values[i]); i++; k = 0; while (k < totalWaypoints) { _spawns[j]._waypoints.Add(new fantasyBot.Waypoints(k)); _spawns[j]._waypoints[k].ID = k; _spawns[j]._waypoints[k].posX = Int32.Parse(values[i++]); _spawns[j]._waypoints[k].posY = Int32.Parse(values[i]); i++; k++; } i++; j++; } } return(true); }
////////////////////////////////////////////////// // Game Functions ////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { arena = invoker as Arena; CFG = arena._server._zoneConfig; _flags = new List <Arena.FlagState>(); minPlayers = 2; victoryHoldTime = CFG.flag.victoryHoldTime; preGamePeriod = CFG.flag.startDelay; killStreaks = new Dictionary <string, PlayerStreak>(); explosives = new Dictionary <string, int>(); bases = new Dictionary <string, Base>(); for (int i = 0; i < explosiveList.Length; i++) { explosives.Add(explosiveList[i], explosiveAliveTimes[i]); } foreach (Arena.FlagState fs in arena._flags.Values) { //Determine the minimum number of players if (fs.flag.FlagData.MinPlayerCount < minPlayers) { minPlayers = fs.flag.FlagData.MinPlayerCount; } //Register our flag change events fs.TeamChange += OnFlagChange; } gameState = GameState.Init; if (arena._name.ToLower().Contains("ovd")) { foreach (Arena.FlagState fs in arena._flags.Values) { if (fs.flag.FlagData.MinPlayerCount == 200) { _flags.Add(fs); } } playing = new Team(arena, arena._server); playing._name = "Playing"; playing._id = (short)arena.Teams.Count(); playing._password = ""; playing._owner = null; playing._isPrivate = true; arena.createTeam(playing); bases["A7"] = new Base(21, 474, 9, 483); bases["D7"] = new Base(279, 504, 267, 491); bases["F8"] = new Base(412, 575, 390, 563); bases["F4"] = new Base(422, 271, 413, 263); bases["A5"] = new Base(57, 359, 37, 349); isOVD = true; } else { foreach (Arena.FlagState fs in arena._flags.Values) { if (fs.flag.FlagData.MinPlayerCount == 0) { _flags.Add(fs); } } } return(true); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { //Populate our variables _bot = invoker as Bot; return(true); }
public EventObject(Accessible accessible) : base(accessible) { proxy = Registry.Bus.GetObject<IEventObject> (accessible.Application.Name, new ObjectPath (accessible.path)); // Hack so that managed-dbus can get the alternate name if (accessible.Application is Registry) proxy.Introspect (); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { _bot = invoker as Bot; Log.write(TLog.Normal, "BasicCombatBot by HellSpawn & Shadwd"); return(true); }
/// <summary> /// Initializes events for the event object /// </summary> public static void eventInit(IEventObject obj, bool bParseEvents) { //Initialize variables obj.events = new EventHandlers(obj); obj._sync = new object(); if (bParseEvents) { //Obtain the group type Type type = obj.GetType(); //Initialize all script events foreach (MethodInfo method in type.GetMethods()) { //Look at it's attributes.. foreach (Attribute attr in method.GetCustomAttributes(true)) { //.. until we find an event handler attribute Scripts.Event ehdlr = attr as Scripts.Event; if (ehdlr == null) continue; //Register the event with the group eventobject obj.events[ehdlr.eventname] += new CEventHandler(obj, method.Name); } } } }
/// <summary> /// Triggers an event /// </summary> public static void trigger(IEventObject obj, string name, bool bCautious, params object[] args) { //Attempt to hold the sync object bool bSync = true; if (bCautious) bSync = DdMonitor.TryEnter(obj._sync); else DdMonitor.Enter(obj._sync); //If this would block, queue the request in the threadpool if (!bSync) { //Queue! ThreadPool.QueueUserWorkItem( delegate(object state) { //Reattempt the trigger trigger(obj, name, false, args); } ); //Done return; } try { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) //No? No need to worry return; //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //We're ok, time to invoke it //Custom handler? if (eh.customcaller == null) eh.handler(eh.that, args); else //Allow them to call it eh.customcaller(eh, false, eh.that, args); } } } catch (Exception ex) { //Log Log.write(TLog.Exception, "Exception occured while triggering event (" + name + "):\r\n" + ex.ToString()); } finally { DdMonitor.Exit(obj._sync); } }
/// <summary> /// Calls a singlecast event, returning a value /// </summary> static public object callsync(IEventObject obj, string name, bool bSync, params object[] args) { //Play safe? if (bSync) { using (DdMonitor.Lock(obj._sync)) { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) { //No? No need to worry return(null); } //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) { throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); } //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) { ret = eh.handler(eh.that, args); } else { //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); } //Got our loot, return with it return(ret); } } return(null); } } else { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) { //No? No need to worry return(null); } //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) { throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); } //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) { ret = eh.handler(eh.that, args); } else { //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); } //Got our loot, return with it return(ret); } } return(null); } }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Performs script initialization /// </summary> public bool init(IEventObject invoker) { _bot = invoker as Bot; Log.write(TLog.Normal, "SimpleBot by HellSpawn"); return true; }
/// <summary> /// Triggers an event /// </summary> static public void trigger(IEventObject obj, string name, bool bCautious, params object[] args) { //Attempt to hold the sync object bool bSync = true; if (bCautious) { bSync = DdMonitor.TryEnter(obj._sync); } else { DdMonitor.Enter(obj._sync); } //If this would block, queue the request in the threadpool if (!bSync) { //Queue! ThreadPool.QueueUserWorkItem( delegate(object state) { //Reattempt the trigger trigger(obj, name, false, args); } ); //Done return; } try { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) { //No? No need to worry return; } //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) { throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); } //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //We're ok, time to invoke it //Custom handler? if (eh.customcaller == null) { eh.handler(eh.that, args); } else { //Allow them to call it eh.customcaller(eh, false, eh.that, args); } } } } catch (Exception ex) { //Log Log.write(TLog.Exception, "Exception occured while triggering event (" + name + "):\r\n" + ex.ToString()); } finally { DdMonitor.Exit(obj._sync); } }
/// <summary> /// Instances all available scripts for an invoker /// </summary> public static List<IScript> instanceScripts(IEventObject invoker, string invokerType) { //Get our scripts List<Type> scripts; if (!_invokerScripts.TryGetValue(invokerType, out scripts)) //Invalid bot type! throw new ArgumentException("Invalid invoker type for instancing: " + invokerType); //Instance them all! int instanced = 0; List<IScript> iscripts = new List<IScript>(); foreach (Type script in scripts) { IScript iscript = (IScript)Activator.CreateInstance(script); //Now allow it to initialize bool success = iscript.init(invoker); if (!success) continue; instanced++; //Look though all the methods present foreach (MethodInfo method in script.GetMethods()) { //Look at it's attributes.. foreach (Attribute attr in method.GetCustomAttributes(true)) { //.. until we find event attribute Event ehdlr = attr as Event; if (ehdlr != null) { //Register the event invoker.events[ehdlr.eventname] += new CEventHandler(iscript, method.Name); } } } //Add it to our list iscripts.Add(iscript); } Log.write(TLog.Inane, "Instanced " + instanced + " '" + invokerType + "' scripts."); return iscripts; }