public static void OnScriptCompiled(DOLEvent e, object sender, EventArgs args) { if (!ServerProperties.Properties.LOAD_EXAMPLES) { return; } // Declare our variables m_horses = new RaceHorse[4]; m_racingHorses = new RaceHorse[4]; m_raceStarted = false; m_currentRanking = 0; // Now declare all our horses and their initial position m_horses[0] = new RaceHorse(504406, 436722, 6082); m_horses[0].Name = "Blacky"; m_horses[0].Model = 450; m_horses[0].Size = 50; m_horses[1] = new RaceHorse(504499, 436679, 7484); m_horses[1].Name = "Speedy"; m_horses[1].Model = 449; m_horses[1].Size = 40; m_horses[2] = new RaceHorse(504504, 436830, 6778); m_horses[2].Name = "Lucky"; m_horses[2].Model = 448; m_horses[2].Size = 50; m_horses[3] = new RaceHorse(504416, 436618, 1568); m_horses[3].Name = "Binky"; m_horses[3].Model = 447; m_horses[3].Size = 50; // Add all horses to the world bool good = true; if (!m_horses[0].AddToWorld() || !m_horses[1].AddToWorld() || !m_horses[2].AddToWorld() || !m_horses[3].AddToWorld()) { good = false; } // Declare the timer to check for the racestart m_raceStartTimer = new Timer(30000); m_raceStartTimer.Elapsed += new ElapsedEventHandler(RaceStartTest); m_raceStartTimer.AutoReset = true; m_raceStartTimer.Start(); if (log.IsInfoEnabled) { if (log.IsInfoEnabled) { log.Info("HorseRace Event initialized: " + good); } } }
//Deregister a racing horse and frees the startnumber protected static int UnregisterRacingHorse(RaceHorse horse) { for (int i = 0; i < 4; i++) { if (m_racingHorses[i] == horse) { m_racingHorses[i] = null; return(i); } } return(-1); }
//Registers a racing horse and returns the startnumber protected static int RegisterRacingHorse(RaceHorse horse) { lock (m_horses) { for (int i = 0; i < 4; i++) { if (m_racingHorses[i] == null) { m_racingHorses[i] = horse; return(i); } } return(-1); } }
// Called from a horse when it has finished the race! protected static void HorseFinished(RaceHorse horse) { lock (m_horses) { foreach (GamePlayer ply in horse.Riders) { // Dismount the rider ply.DismountSteed(true); // Unregister the horse from the race and free // the startnumber UnregisterRacingHorse(horse); // If a player was sitting on the horse // (could be that player /quit while on horse) if (ply != null) { // increase the ranking and output message m_currentRanking++; foreach (GamePlayer player in horse.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { player.Out.SendMessage( ply.Name + " has finished the horse race and came in at " + m_currentRanking + ". position!", eChatType.CT_Broadcast, eChatLoc.CL_SystemWindow); } } // Check if all horses are back in finish yet int count = 0; for (int i = 0; i < 4; i++) { if (m_horses[i].HorseState != RaceHorse.RaceHorseState.Racing) { count++; } } // If all horses have finished, reset the race if (count == 4) { m_raceStarted = false; m_currentRanking = 0; } } } }
//Deregister a racing horse and frees the startnumber protected static int UnregisterRacingHorse(RaceHorse horse) { for (int i = 0; i < 4; i++) if (m_racingHorses[i] == horse) { m_racingHorses[i] = null; return i; } return -1; }
//Registers a racing horse and returns the startnumber protected static int RegisterRacingHorse(RaceHorse horse) { lock (m_horses) { for (int i = 0; i < 4; i++) if (m_racingHorses[i] == null) { m_racingHorses[i] = horse; return i; } return -1; } }
//Called from a horse when it has finished the race! protected static void HorseFinished(RaceHorse horse) { lock (m_horses) { foreach (GamePlayer ply in horse.Riders) { //Dismount the rider ply.DismountSteed(true); //Unregister the horse from the race and free //the startnumber UnregisterRacingHorse(horse); //If a player was sitting on the horse //(could be that player /quit while on horse) if (ply != null) { //increase the ranking and output message m_currentRanking++; foreach (GamePlayer player in horse.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) player.Out.SendMessage( ply.Name + " has finished the horse race and came in at " + m_currentRanking + ". position!", eChatType.CT_Broadcast, eChatLoc.CL_SystemWindow); } //Check if all horses are back in finish yet int count = 0; for (int i = 0; i < 4; i++) { if (m_horses[i].HorseState != RaceHorse.RaceHorseState.Racing) count++; } //If all horses have finished, reset the race if (count == 4) { m_raceStarted = false; m_currentRanking = 0; } } } }
public static void OnScriptCompiled(DOLEvent e, object sender, EventArgs args) { if (!ServerProperties.Properties.LOAD_EXAMPLES) return; //Declare our variables m_horses = new RaceHorse[4]; m_racingHorses = new RaceHorse[4]; m_raceStarted = false; m_currentRanking = 0; //Now declare all our horses and their initial position m_horses[0] = new RaceHorse(504406, 436722, 6082); m_horses[0].Name = "Blacky"; m_horses[0].Model = 450; m_horses[0].Size = 50; m_horses[1] = new RaceHorse(504499, 436679, 7484); m_horses[1].Name = "Speedy"; m_horses[1].Model = 449; m_horses[1].Size = 40; m_horses[2] = new RaceHorse(504504, 436830, 6778); m_horses[2].Name = "Lucky"; m_horses[2].Model = 448; m_horses[2].Size = 50; m_horses[3] = new RaceHorse(504416, 436618, 1568); m_horses[3].Name = "Binky"; m_horses[3].Model = 447; m_horses[3].Size = 50; //Add all horses to the world bool good = true; if (!m_horses[0].AddToWorld() || !m_horses[1].AddToWorld() || !m_horses[2].AddToWorld() || !m_horses[3].AddToWorld()) good = false; //Declare the timer to check for the racestart m_raceStartTimer = new Timer(30000); m_raceStartTimer.Elapsed += new ElapsedEventHandler(RaceStartTest); m_raceStartTimer.AutoReset = true; m_raceStartTimer.Start(); if (log.IsInfoEnabled) if (log.IsInfoEnabled) log.Info("HorseRace Event initialized: "+good); }