public string Execute( IProtoVehicle objTypeName, double x, double y) { var offset = Server.World.WorldBounds.Offset; return(SpawnObject(objTypeName, (x + offset.X, y + offset.Y))); }
public void SpawnEntity() { if (!occupied) { int randomIndex = Random.Range(0, entitiesToSpawn.Length); //float sizeModifier = Random.Range(modifyMultiplicatorMin, modifyMultiplicatorMax); Debug.Log(randomIndex); Transform entityToSpawn = entitiesToSpawn[randomIndex]; //entityToSpawn.localScale = new Vector3(0.3f, 0.3f, 0.3f); //Transform spawnPosition = this.gameObject.transform; var spawnedEntity = Instantiate(entityToSpawn, transform.position, transform.rotation); if (spawnedEntity != null) { SpawnObject spawnObj = spawnedEntity.GetComponent <SpawnObject>(); if (spawnObj != null) { spawnObj.parentSpawn = this; occupied = true; } } } }
void Start() { List <GameObject> rocks = new List <GameObject> { Resources.Load <GameObject>("Prefabs/Rocks/Cluster/RockCluster1"), Resources.Load <GameObject>("Prefabs/Rocks/Cluster/RockCluster2"), Resources.Load <GameObject>("Prefabs/Rocks/Cluster/RockCluster3"), Resources.Load <GameObject>("Prefabs/Rocks/Cluster/RockCluster4"), Resources.Load <GameObject>("Prefabs/Rocks/Cluster/RockCluster5") }; types[0] = new SpawnObject(rocks, Constants.rockSpawnTime); List <GameObject> waves = new List <GameObject> { Resources.Load <GameObject>("Sprites/Tilesets/Prefabs/Wave") }; types[1] = new SpawnObject(waves, Constants.waveSpawnTime); List <GameObject> enemies = new List <GameObject> { Resources.Load <GameObject>("Prefabs/Ships/EnemyShip") }; types[2] = new SpawnObject(enemies, Constants.enemySpawnTime); if (Constants.spawning) { InvokeRepeating("SpawnObstacles", 0f, spawnCheckInterval); } }
public void OnTriggerEnter(Collider other) { //When gun pickup is touched foreach (Gun _gun in possibleGuns) { if (_gun.name == other.gameObject.tag) { SpawnObject spawner = other.transform.parent.GetComponent <SpawnObject>(); spawner.Invoke("CreateNewObject", spawner.coolDown); timeBetweenShots = _gun.timeToNextShot; currentGun = _gun; Destroy(other.gameObject); Debug.Log("Item collected"); } } //When ammo is touched if (other.gameObject.tag == "Ammo") { SpawnObject spawner = other.transform.parent.GetComponent <SpawnObject>(); spawner.Invoke("CreateNewObject", spawner.coolDown); ammoLeft += other.gameObject.GetComponent <GiveAmmo>().ammoToGive; Destroy(other.gameObject); } }
public void Spawn(SpawnObject so, CoordDouble playerPos) { if (so.Type != Vehicles.Item) { return; } if (playerPos.Y > 50) { return; //Above ground probably a self created ore } //if (so.SourceEntity == 1) //break; //if (so..Item.Count != 1) // break; if (so.Position.DistanceTo(playerPos) > 10) { return; //Too far away, not your dig } if (DateTime.Now - BrokeBlock > TimeSpan.FromSeconds(3)) { return; //not from block broken } //DO track TrackEID = so.EID; }
private void Update() { //If we go through a loop without spawning anything or decrementing a timer bool m_haveSpawnedAll = true; for (int i = 0; i < m_objectsToSpawn.Count; i++) { if (!m_objectsToSpawn[i].SpawnImmidiately && m_objectsToSpawn[i].SpawnAmount > 0) { m_haveSpawnedAll = false; SpawnObject so = m_objectsToSpawn[i]; so.IntervalTimer -= Time.deltaTime; if (so.IntervalTimer <= 0) { GameObject temp = Instantiate(so.Spawn, gameObject.transform, true); temp.transform.position = m_collider.RandomPointInBox(); //Decrement the amount we have left to spawn so.SpawnAmount--; so.IntervalTimer = so.SpawnInterval; } m_objectsToSpawn[i] = so; } } //Turn off this spawner if (m_haveSpawnedAll) { enabled = false; } }
public void AlignZHeight(SpawnObject obj) { double height = Host.me.Z - obj.Z; double mapZHeight = Host.getZFromHeightMap(Host.me.X, Host.me.Y); if (Math.Abs(height) <= 1 || (Host.me.Z - mapZHeight) <= 1) { Host.SwimUp(false); Host.SwimDown(false); return; } if (height > 0) { if (Host.swimUpState) { Host.SwimUp(false); } Host.SwimDown(true); } else { if (Host.swimDownState) { Host.SwimDown(false); } Host.SwimUp(true); } }
public void RandomLooking(Func <bool> eval) { SpawnObject viewpoint = null; var players = Host.getCreatures().Where (c => Host.dist(c) < 40 && (c.type == BotTypes.Player || c.type == BotTypes.Npc)); if (players.Count() > 0) { if (Utils.RandomNum(0, 1) < 1) { players = players.OrderBy(c => Host.dist(c)); } else { players = players.OrderByDescending(c => Host.dist(c)); } viewpoint = players.FirstOrDefault(); } if (viewpoint != null) { RotateTo(viewpoint.X, viewpoint.Y, 20, eval); } }
private void OnSkillCasting(Creature obj, SpawnObject obj2, Skill skill, double x, double y, double z) { if (obj.type == BotTypes.Player && (obj2 == Host.me) && (skill.id == 20256)) { stats.SuspectReports++; } }
private void Spawn(SpawnObject spawnObject) { var spawnPosition = Utility.GetRandomPointOnNavMesh(playerTransform.position, spawnObject.maxDistance, NavMesh.AllAreas); spawnPosition += Vector3.up * spawnObject.spawnHeight; var selectedObject = spawnObject.poolItemName[Random.Range(0, spawnObject.poolItemName.Length)]; var createObject = ObjectPoolingManager.Instance.PopFromPool(selectedObject); if (createObject != null) { createObject.transform.position = spawnPosition; createObject.transform.rotation = Quaternion.identity; createObject.transform.localScale = spawnObject.objectScale; createObject.SetActive(true); } // Setting Skill DisappearTime if (spawnObject.isSkill) { var effectController = createObject.GetComponent <EffectController>(); if (effectController != null) { effectController.enabled = true; spawnObject.disappearTime = effectController.EffectDisableTime; } } StartCoroutine(PushToPoolSpawnObject(selectedObject, spawnObject.disappearTime, createObject)); }
IEnumerator nofall() { partsys.transform.position = transform.position; partsys.startSpeed = 2.0f; partsys.startSize = 0.2f; partsys.maxParticles = 200; partsys.startColor = new Color(0.6f, 0.8f, 0.2f); partsys.Clear(); partsys.Stop(); partsys.Emit(200); yield return(new WaitForSeconds(0.2f)); vxe.changeChunkMaterial(chunkCoords, BiomeScript.Instance.getBiomeMaterialFromCoords(chunkCoords)); if (!cannotFall) { SpawnObject sobj = this.gameObject.AddComponent <SpawnObject> (); EnvironmentSpawner.Instance.spawns.push(sobj); } if (popEventHandler != null) { popEventHandler(); } }
private void SpawnOneObject(SpawnObject _object, float yOffset) { Vector2 spawnPosition = new Vector2(Random.Range(_object.FirstCoordinate.x, _object.SecondCoordinate.x), Random.Range(_object.FirstCoordinate.y, _object.SecondCoordinate.y) + yOffset); Instantiate(_object.SpawnObj, spawnPosition, Quaternion.identity); }
private void RemoveObjectFromRadar(SpawnObject o) { //do not remove housing from radar, since they don't move if (o.type == BotTypes.Housing) { return; } UIElement vec = LookupVector(o.objId); UIElement txt = LookupText(o.objId); UIElement dot = LookupDot(o.objId); if (vec != null) { RadarCanvas.Children.Remove(vec); } if (txt != null) { RadarCanvas.Children.Remove(txt); } if (dot != null) { RadarCanvas.Children.Remove(dot); } PurgeVector(o.objId); PurgeText(o.objId); PurgeDot(o.objId); }
// Use this for initialization void Start() { ins = Camera.main.GetComponent <Inspector>(); spawnOBJ = Camera.main.GetComponent <SpawnObject>(); insu = new InspectorUtils(); keyHandler = Camera.main.GetComponent <KeyHandler>(); }
public Material temporaryColor; //set in Inspector: material for the temporary line // Start is called before the first frame update void Start() { lastMousePosition = new Vector3(0, 0, 0); //have a Vector3 ready ic = new IntersectionChecker(); spawner = this.gameObject.GetComponent <SpawnObject>(); camera = GameObject.FindGameObjectsWithTag("MainCamera")[0].GetComponent <Camera>(); SetupNewObject(); //set up a first object to be drawn }
private void OnSkillCasting(Creature obj, SpawnObject obj2, Skill skill, double x, double y, double z) { if (obj.type == BotTypes.Player && obj2 == Host.me && skill.id == 20256) { stats.SuspectReports += 1; UI.GameLog($"You have been reported by: {obj.name}"); } }
IEnumerator ActiveAndPositionObject(SpawnObject so) { while (true) { so.ActiveRandomObject(); yield return(new WaitForSeconds(Random.Range(so.minTimeToSpawn, so.maxTimeToSpawn))); } }
private IEnumerator SpawnObjectRoutine(SpawnObject spawnObject) { for (int i = 0; i < spawnObject.amount; i++) { yield return(new WaitForSeconds(spawnObject.delay)); spawnBehaviour.Spawn(spawnObject.prefab); } }
// Use this for initialization void Start() { myHealthbar = myObject.GetComponent <Healthbar>(); GameObject Pacmanobject = GameObject.FindWithTag("pacman"); if (Pacmanobject != null) { spawnobject = Pacmanobject.GetComponent <SpawnObject>(); } }
public override void OnEnable() { headerName = HeaderAnimatorAddonName; headerColor = HeaderAnimatorAddonColor; base.OnEnable(); _target = (SpawnObject)target; _target.AddToSpawnList(); }
private void Start() { alcoholMeter = FindObjectOfType <AlcoholMeter>(); spawnAlcohol = FindObjectOfType <SpawnObject>(); scoreCalculator = FindObjectOfType <ScoreCalculator>(); playerCollisions = FindObjectOfType <PlayerCollisions>(); objectives = FindObjectOfType <Objectives>(); blink = FindObjectOfType <BlinkingEffect>(); carSound = FindObjectOfType <CarSound>(); audioSource = FindObjectOfType <AudioSource>(); }
void OnTriggerExit(Collider other) { if (other.tag == "Interactable") { VRInteractables.Remove(other.GetComponent <VRInteractable>()); } else if (other.tag == "Spawner") { inSpawner = false; spawner = null; } }
void SelfDestroy() { SpawnObject tSP = GetComponentInChildren <SpawnObject>(); if (tSP != null) { tSP.Remove(); } else { Destroy(gameObject, TimeToLive); } }
public void GetByID_OneItem_ReturnsSpawnObject() { // Arrange SpawnObject entity = new SpawnObject { ID = 1 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObject>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(1)); }
private void OnTriggerEnter(Collider other) { SpawnObject tSP = other.GetComponentInChildren <SpawnObject>(); if (tSP != null) { tSP.Remove(); //If a Spawn item use Pool Methods to re-pool } else { Destroy(other.gameObject); //if not Kill item directly } }
public Dictionary <SpawnType, List <GameObject> > InitializeSpawnObjects() { var spawnObjectList = Assembly.GetAssembly(typeof(SpawnObject)).GetTypes() .Where(myList => myList.IsClass && !myList.IsAbstract && myList.IsSubclassOf(typeof(SpawnObject))); spawnObjects = new Dictionary <SpawnType, List <GameObject> >(); foreach (var spawnObj in spawnObjectList) { SpawnObject tmpSpawnObj = Activator.CreateInstance(spawnObj) as SpawnObject; spawnObjects.Add(tmpSpawnObj.spawnType, tmpSpawnObj.spawnList); } return(spawnObjects); }
private void OnTriggerEnter(Collider other) { if (other.tag == "Interactable") { VRInteractables.Add(other.gameObject.GetComponent <VRInteractable>()); //SteamVR_Controller.Input((int)trackedObj.index).TriggerHapticPulse(500); } else if (other.tag == "Spawner") { inSpawner = true; spawner = other.gameObject.GetComponent <SpawnObject>(); } }
public SpawnObject PoolSpawn(Vector3 vPosition, Quaternion vRotation) { SpawnObject tSO = FindFreeObject(); //Get first free one from pool if (tSO != null) //Do we have items to use { tSO.transform.SetParent(null); //Unparent UsedPool.Add(tSO); //Add it to used Pool tSO.Reset(vPosition, vRotation); //Reset to defaults return(tSO); //Success } Debug.LogFormat("Pool empty cannot allocate SpawnObject"); return(null); //Pool Deleted }
public void PoolDestroy(SpawnObject vSO) { Debug.AssertFormat(vSO != null, "Invalid Object"); if (UsedPool.Remove(vSO)) { vSO.Show(false); //Turn Off vSO.transform.SetParent(transform); //Parent to pool UnusedPool.Add(vSO); //Add back to Unused Pool } else { Debug.LogFormat("Object {0} not in Used Pool", vSO.name); } }
IEnumerator CreateBeginingBG(SpawnObject so) { float endMapX = 8f; Vector3 currentSpawnPoint = new Vector3(-8f, so.spawnPoint.position.y, so.spawnPoint.position.z); while (currentSpawnPoint.x < endMapX) { // Random position float offSet = Random.Range(minDistanceSpawn, maxDistanceSpawn); currentSpawnPoint += new Vector3(offSet, 0, 0); // enable and set Object on new position so.ActiveRandomObject(currentSpawnPoint); yield return(null); } }
private static void ImportMegaSpawner( Mobile from, XmlElement node ) { string name = GetText( node["Name"], "MegaSpawner" ); bool running = bool.Parse( GetText( node["Active"], "True" ) ); Point3D location = Point3D.Parse( GetText( node["Location"], "Error" ) ); Map map = Map.Parse( GetText( node["Map"], "Error" ) ); int team = 0; bool group = false; int maxcount = 0; // default maxcount of the spawner int homeRange = 4; // default homerange int spawnRange = 4; // default homerange TimeSpan maxDelay = TimeSpan.FromMinutes( 10 ); TimeSpan minDelay = TimeSpan.FromMinutes( 5 ); XmlElement listnode = node["EntryLists"]; int nentries = 0; SpawnObject[] so = null; if( listnode != null ) { // get the number of entries if( listnode.HasAttributes ) { XmlAttributeCollection attr = listnode.Attributes; nentries = int.Parse( attr.GetNamedItem( "count" ).Value ); } if( nentries > 0 ) { so = new SpawnObject[nentries]; int entrycount = 0; bool diff = false; foreach( XmlElement entrynode in listnode.GetElementsByTagName( "EntryList" ) ) { // go through each entry and add a spawn object for it if( entrynode != null ) { if( entrycount == 0 ) { // get the spawner defaults from the first entry // dont handle the individually specified entry attributes group = bool.Parse( GetText( entrynode["GroupSpawn"], "False" ) ); maxDelay = TimeSpan.FromSeconds( int.Parse( GetText( entrynode["MaxDelay"], "10:00" ) ) ); minDelay = TimeSpan.FromSeconds( int.Parse( GetText( entrynode["MinDelay"], "05:00" ) ) ); homeRange = int.Parse( GetText( entrynode["WalkRange"], "10" ) ); spawnRange = int.Parse( GetText( entrynode["SpawnRange"], "4" ) ); } else { // just check for consistency with other entries and report discrepancies if( group != bool.Parse( GetText( entrynode["GroupSpawn"], "False" ) ) ) { diff = true; // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "MSFimport : individual group entry difference: {0} vs {1}", GetText( entrynode["GroupSpawn"], "False" ), group ); } } catch { } } if( minDelay != TimeSpan.FromSeconds( int.Parse( GetText( entrynode["MinDelay"], "05:00" ) ) ) ) { diff = true; // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "MSFimport : individual mindelay entry difference: {0} vs {1}", GetText( entrynode["MinDelay"], "05:00" ), minDelay ); } } catch { } } if( maxDelay != TimeSpan.FromSeconds( int.Parse( GetText( entrynode["MaxDelay"], "10:00" ) ) ) ) { diff = true; // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "MSFimport : individual maxdelay entry difference: {0} vs {1}", GetText( entrynode["MaxDelay"], "10:00" ), maxDelay ); } } catch { } } if( homeRange != int.Parse( GetText( entrynode["WalkRange"], "10" ) ) ) { diff = true; // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "MSFimport : individual homerange entry difference: {0} vs {1}", GetText( entrynode["WalkRange"], "10" ), homeRange ); } } catch { } } if( spawnRange != int.Parse( GetText( entrynode["SpawnRange"], "4" ) ) ) { diff = true; // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "MSFimport : individual spawnrange entry difference: {0} vs {1}", GetText( entrynode["SpawnRange"], "4" ), spawnRange ); } } catch { } } } // these apply to individual entries int amount = int.Parse( GetText( entrynode["Amount"], "1" ) ); string entryname = GetText( entrynode["EntryType"], "" ); // keep track of the maxcount for the spawner by adding the individual amounts maxcount += amount; // add the creature entry so[entrycount] = new SpawnObject( entryname, amount ); entrycount++; if( entrycount > nentries ) { // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "{0} MSFImport Error; inconsistent entry count {1} {2}", DateTime.Now, location, map ); op.WriteLine(); } } catch { } from.SendMessage( "Inconsistent entry count detected at {0} {1}.", location, map ); break; } } } if( diff ) { from.SendMessage( "Individual entry setting detected at {0} {1}.", location, map ); // log it try { using( StreamWriter op = new StreamWriter( "badimport.log", true ) ) { op.WriteLine( "{0} MSFImport: Individual entry setting differences listed above from spawner at {1} {2}", DateTime.Now, location, map ); op.WriteLine(); } } catch { } } } } // assign it a unique id Guid SpawnId = Guid.NewGuid(); // Create the new xml spawner XmlSpawner spawner = new XmlSpawner( SpawnId, location.X, location.Y, 0, 0, name, maxcount, minDelay, maxDelay, TimeSpan.FromMinutes( 0 ), -1, defaultTriggerSound, 1, team, homeRange, false, so, TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), null, null, null, null, null, null, null, null, null, 1, null, group, defTODMode, defKillReset, false, -1, null, false, false, false, null, defDespawnTime, null, false, null ); spawner.SpawnRange = spawnRange; spawner.m_PlayerCreated = true; string fromname = null; if( from != null ) fromname = from.Name; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; // Try to find a valid Z height if required (Z == -999) if( location.Z == -999 ) { int NewZ = map.GetAverageZ( location.X, location.Y ); if( map.CanFit( location.X, location.Y, NewZ, SpawnFitSize ) == false ) { for( int x = 1; x <= 39; x++ ) { if( map.CanFit( location.X, location.Y, NewZ + x, SpawnFitSize ) ) { NewZ += x; break; } } } location.Z = NewZ; } spawner.MoveToWorld( location, map ); if( !IsValidMapLocation( location, spawner.Map ) ) { spawner.Delete(); throw new Exception( "Invalid spawner location." ); } }
private static void ImportSpawner( XmlElement node, Mobile from ) { int count = int.Parse( GetText( node["count"], "1" ) ); int homeRange = int.Parse( GetText( node["homerange"], "4" ) ); int walkingRange = int.Parse( GetText( node["walkingrange"], "-1" ) ); // width of the spawning area int spawnwidth = homeRange * 2; if( walkingRange >= 0 ) spawnwidth = walkingRange * 2; int team = int.Parse( GetText( node["team"], "0" ) ); bool group = bool.Parse( GetText( node["group"], "False" ) ); TimeSpan maxDelay = TimeSpan.Parse( GetText( node["maxdelay"], "10:00" ) ); TimeSpan minDelay = TimeSpan.Parse( GetText( node["mindelay"], "05:00" ) ); ArrayList creaturesName = LoadCreaturesName( node["creaturesname"] ); string name = GetText( node["name"], "Spawner" ); Point3D location = Point3D.Parse( GetText( node["location"], "Error" ) ); Map map = Map.Parse( GetText( node["map"], "Error" ) ); // allow it to make an xmlspawner instead // first add all of the creatures on the list SpawnObject[] so = new SpawnObject[creaturesName.Count]; bool hasvendor = false; for( int i = 0; i < creaturesName.Count; i++ ) { so[i] = new SpawnObject( (string)creaturesName[i], count ); // check the type to see if there are vendors on it Type type = SpawnerType.GetType( (string)creaturesName[i] ); // if it has basevendors on it or invalid types, then skip it if( type != null && (type == typeof( BaseVendor ) || type.IsSubclassOf( typeof( BaseVendor ) )) ) { hasvendor = true; } } // assign it a unique id Guid SpawnId = Guid.NewGuid(); // Create the new xml spawner XmlSpawner spawner = new XmlSpawner( SpawnId, location.X, location.Y, spawnwidth, spawnwidth, name, count, minDelay, maxDelay, TimeSpan.FromMinutes( 0 ), -1, defaultTriggerSound, 1, team, homeRange, false, so, TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), null, null, null, null, null, null, null, null, null, 1, null, group, defTODMode, defKillReset, false, -1, null, false, false, false, null, defDespawnTime, null, false, null ); if( hasvendor ) { spawner.SpawnRange = 0; } else { spawner.SpawnRange = homeRange; } spawner.m_PlayerCreated = true; string fromname = null; if( from != null ) fromname = from.Name; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; spawner.MoveToWorld( location, map ); if( !IsValidMapLocation( location, spawner.Map ) ) { spawner.Delete(); throw new Exception( "Invalid spawner location." ); } }
private static void ParseOldMapFormat( Mobile from, string filename, string line, string[] args, int linenumber, ref int spawnercount, ref int badspawnercount, ref int overridemap, ref double overridemintime, ref double overridemaxtime ) { // format of each .map line is * Dragon:Wyvern 5209 965 -40 2 2 10 50 30 1 // * typename:typename:... x y z map mindelay maxdelay homerange spawnrange maxcount // or // * typename:typename:... x y z map mindelay maxdelay homerange spawnrange spawnid maxcount // ## are comments // overridemap mapnumber // map 0 is tram+fel // map 1 is fel // map 2 is tram // map 3 is ilsh // map 4 is mal // map 5 is tokuno // // * | typename:typename:... | | | | | | x | y | z | map | mindelay maxdelay homerange spawnrange spawnid maxcount | maxcount2 | maxcount2 | maxcount3 | maxcount4 | maxcount5 // the new format of each .map line is * |Dragon:Wyvern| spawns:spawns| | | | | 5209 | 965 | -40 | 2 | 2 | 10 | 50 | 30 | 1 if( args == null || from == null ) return; // look for the override keyword if( args.Length == 2 && (args[0].ToLower() == "overridemap") ) { try { overridemap = int.Parse( args[1] ); } catch { } } else if( args.Length == 2 && (args[0].ToLower() == "overridemintime") ) { try { overridemintime = double.Parse( args[1] ); } catch { } } else if( args.Length == 2 && (args[0].ToLower() == "overridemaxtime") ) { try { overridemaxtime = double.Parse( args[1] ); } catch { } } else // look for a spawn spec line if( args.Length > 0 && (args[0] == "*") ) { bool badspawn = false; int x = 0; int y = 0; int z = 0; int map = 0; double mindelay = 0; double maxdelay = 0; int homerange = 0; int spawnrange = 0; int maxcount = 0; int spawnid = 0; string[] typenames = null; if( args.Length != 11 && args.Length != 12 ) { badspawn = true; from.SendMessage( "Invalid arg count {1} at line {0}", linenumber, args.Length ); } else { // get the list of spawns typenames = args[1].Split( ':' ); // parse the rest of the args if( args.Length == 11 ) { try { x = int.Parse( args[2] ); y = int.Parse( args[3] ); z = int.Parse( args[4] ); map = int.Parse( args[5] ); mindelay = double.Parse( args[6] ); maxdelay = double.Parse( args[7] ); homerange = int.Parse( args[8] ); spawnrange = int.Parse( args[9] ); maxcount = int.Parse( args[10] ); } catch { from.SendMessage( "Parsing error at line {0}", linenumber ); badspawn = true; } } else if( args.Length == 12 ) { try { x = int.Parse( args[2] ); y = int.Parse( args[3] ); z = int.Parse( args[4] ); map = int.Parse( args[5] ); mindelay = double.Parse( args[6] ); maxdelay = double.Parse( args[7] ); homerange = int.Parse( args[8] ); spawnrange = int.Parse( args[9] ); spawnid = int.Parse( args[10] ); maxcount = int.Parse( args[11] ); } catch { from.SendMessage( "Parsing error at line {0}", linenumber ); badspawn = true; } } } // apply mi/maxdelay overrides if( overridemintime != -1 ) { mindelay = overridemintime; } if( overridemaxtime != -1 ) { maxdelay = overridemaxtime; } if( mindelay > maxdelay ) maxdelay = mindelay; if( !badspawn && typenames != null && typenames.Length > 0 ) { // everything seems ok so go ahead and make the spawner // check for map override if( overridemap >= 0 ) map = overridemap; Map spawnmap = Map.Internal; switch( map ) { case 0: spawnmap = Map.Felucca; // note it also does trammel break; case 1: spawnmap = Map.Felucca; break; case 2: spawnmap = Map.Trammel; break; case 3: spawnmap = Map.Ilshenar; break; case 4: spawnmap = Map.Malas; break; case 5: spawnmap = Map.Tokuno; break; } if( !IsValidMapLocation( x, y, spawnmap ) ) { // invalid so dont spawn it badspawnercount++; from.SendMessage( "Invalid map/location at line {0}", linenumber ); from.SendMessage( "Bad spawn at line {1}: {0}", line, linenumber ); return; } // allow it to make an xmlspawner instead // first add all of the creatures on the list SpawnObject[] so = new SpawnObject[typenames.Length]; bool hasvendor = true; for( int i = 0; i < typenames.Length; i++ ) { so[i] = new SpawnObject( typenames[i], maxcount ); // check the type to see if there are vendors on it Type type = SpawnerType.GetType( typenames[i] ); // check for vendor-only spawners which get special spawnrange treatment if( type != null && (type != typeof( BaseVendor ) && !type.IsSubclassOf( typeof( BaseVendor ) )) ) { hasvendor = false; } } // assign it a unique id Guid SpawnId = Guid.NewGuid(); // and give it a name based on the spawner count and file string spawnername = String.Format( "{0}#{1}", Path.GetFileNameWithoutExtension( filename ), spawnercount ); // Create the new xml spawner XmlSpawner spawner = new XmlSpawner( SpawnId, x, y, 0, 0, spawnername, maxcount, TimeSpan.FromMinutes( mindelay ), TimeSpan.FromMinutes( maxdelay ), TimeSpan.FromMinutes( 0 ), -1, defaultTriggerSound, 1, 0, homerange, false, so, TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), null, null, null, null, null, null, null, null, null, 1, null, false, defTODMode, defKillReset, false, -1, null, false, false, false, null, TimeSpan.FromHours( 0 ), null, false, null ); if( hasvendor ) { // force vendor spawners to behave like the distro spawner.SpawnRange = 0; } else { spawner.SpawnRange = spawnrange; } spawner.m_PlayerCreated = true; string fromname = null; if( from != null ) fromname = from.Name; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; spawner.MoveToWorld( new Point3D( x, y, z ), spawnmap ); if( spawner.Map == Map.Internal ) { badspawnercount++; spawner.Delete(); from.SendMessage( "Invalid map at line {0}", linenumber ); from.SendMessage( "Bad spawn at line {1}: {0}", line, linenumber ); return; } spawnercount++; // handle the special case of map 0 that also needs to do trammel if( map == 0 ) { spawnmap = Map.Trammel; // assign it a unique id SpawnId = Guid.NewGuid(); // Create the new xml spawner spawner = new XmlSpawner( SpawnId, x, y, 0, 0, spawnername, maxcount, TimeSpan.FromMinutes( mindelay ), TimeSpan.FromMinutes( maxdelay ), TimeSpan.FromMinutes( 0 ), -1, defaultTriggerSound, 1, 0, homerange, false, so, TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), TimeSpan.FromMinutes( 0 ), null, null, null, null, null, null, null, null, null, 1, null, false, defTODMode, defKillReset, false, -1, null, false, false, false, null, TimeSpan.FromHours( 0 ), null, false, null ); spawner.SpawnRange = spawnrange; spawner.m_PlayerCreated = true; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; spawner.MoveToWorld( new Point3D( x, y, z ), spawnmap ); if( spawner.Map == Map.Internal ) { badspawnercount++; spawner.Delete(); from.SendMessage( "Bad spawn at line {1}: {0}", line, linenumber ); return; } spawnercount++; } } else { badspawnercount++; from.SendMessage( "Bad spawn at line {1}: {0}", line, linenumber ); } } }
public void LoadXmlConfig( string filename ) { if( filename == null || filename.Length <= 0 ) return; // Check if the file exists if( System.IO.File.Exists( filename ) == true ) { FileStream fs = null; try { fs = File.Open( filename, FileMode.Open, FileAccess.Read ); } catch { } if( fs == null ) { status_str = String.Format( "Unable to open {0} for loading", filename ); return; } // Create the data set DataSet ds = new DataSet( XmlDataSetName ); // Read in the file bool fileerror = false; try { ds.ReadXml( fs ); } catch { fileerror = true; } // close the file fs.Close(); if( fileerror ) { Console.WriteLine( "XmlSpawner: Error in XML config file '{0}'", filename ); return; } // Check that at least a single table was loaded if( ds.Tables != null && ds.Tables.Count > 0 ) { if( ds.Tables[XmlTableName] != null && ds.Tables[XmlTableName].Rows.Count > 0 ) { foreach( DataRow dr in ds.Tables[XmlTableName].Rows ) { bool valid_entry; string strEntry = null; bool boolEntry = true; double doubleEntry = 0; int intEntry = 0; valid_entry = true; try { strEntry = (string)dr["Name"]; } catch { valid_entry = false; } if( valid_entry ) { Name = strEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["X"] ); } catch { valid_entry = false; } if( valid_entry ) { m_X = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Y"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Y = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Width"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Width = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Height"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Height = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["CentreX"] ); } catch { valid_entry = false; } if( valid_entry ) { X = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["CentreY"] ); } catch { valid_entry = false; } if( valid_entry ) { Y = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["CentreZ"] ); } catch { valid_entry = false; } if( valid_entry ) { Z = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["SequentialSpawning"] ); } catch { valid_entry = false; } if( valid_entry ) { m_SequentialSpawning = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["ProximityRange"] ); } catch { valid_entry = false; } if( valid_entry ) { m_ProximityRange = intEntry; } valid_entry = true; try { strEntry = (string)dr["ProximityTriggerMessage"]; } catch { valid_entry = false; } if( valid_entry ) { m_ProximityTriggerMessage = strEntry; } valid_entry = true; try { strEntry = (string)dr["SpeechTrigger"]; } catch { valid_entry = false; } if( valid_entry ) { m_SpeechTrigger = strEntry; } valid_entry = true; try { strEntry = (string)dr["SkillTrigger"]; } catch { valid_entry = false; } if( valid_entry ) { m_SkillTrigger = strEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["ProximityTriggerSound"] ); } catch { valid_entry = false; } if( valid_entry ) { m_ProximityTriggerSound = intEntry; } valid_entry = true; try { strEntry = (string)dr["ItemTriggerName"]; } catch { valid_entry = false; } if( valid_entry ) { m_ItemTriggerName = strEntry; } valid_entry = true; try { strEntry = (string)dr["NoItemTriggerName"]; } catch { valid_entry = false; } if( valid_entry ) { m_NoItemTriggerName = strEntry; } // check for the delayinsec entry bool delayinsec = false; try { delayinsec = bool.Parse( (string)dr["DelayInSec"] ); } catch { } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["MinDelay"] ); } catch { valid_entry = false; } if( valid_entry ) { if( delayinsec ) m_MinDelay = TimeSpan.FromSeconds( doubleEntry ); else m_MinDelay = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["MaxDelay"] ); } catch { valid_entry = false; } if( valid_entry ) { if( delayinsec ) m_MaxDelay = TimeSpan.FromSeconds( doubleEntry ); else m_MaxDelay = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["Duration"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Duration = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["DespawnTime"] ); } catch { valid_entry = false; } if( valid_entry ) { m_DespawnTime = TimeSpan.FromHours( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["MinRefractory"] ); } catch { valid_entry = false; } if( valid_entry ) { m_MinRefractory = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["MaxRefractory"] ); } catch { valid_entry = false; } if( valid_entry ) { m_MaxRefractory = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["TODStart"] ); } catch { valid_entry = false; } if( valid_entry ) { m_TODStart = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["TODEnd"] ); } catch { valid_entry = false; } if( valid_entry ) { m_TODEnd = TimeSpan.FromMinutes( doubleEntry ); } valid_entry = true; try { intEntry = int.Parse( (string)dr["TODMode"] ); } catch { valid_entry = false; } if( valid_entry ) { m_TODMode = (TODModeType)intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Amount"] ); } catch { valid_entry = false; } if( valid_entry ) { m_StackAmount = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["MaxCount"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Count = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Range"] ); } catch { valid_entry = false; } if( valid_entry ) { m_HomeRange = intEntry; } valid_entry = true; try { intEntry = int.Parse( (string)dr["Team"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Team = intEntry; } valid_entry = true; try { strEntry = (string)dr["WayPoint"]; } catch { valid_entry = false; } if( valid_entry ) { m_WayPoint = GetWaypoint( strEntry ); } valid_entry = true; try { intEntry = int.Parse( (string)dr["KillReset"] ); } catch { valid_entry = false; } if( valid_entry ) { m_KillReset = intEntry; } valid_entry = true; try { doubleEntry = double.Parse( (string)dr["TriggerProbability"] ); } catch { valid_entry = false; } if( valid_entry ) { m_TriggerProbability = doubleEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["ExternalTriggering"] ); } catch { valid_entry = false; } if( valid_entry ) { m_ExternalTriggering = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["IsGroup"] ); } catch { valid_entry = false; } if( valid_entry ) { m_Group = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["IsHomeRangeRelative"] ); } catch { valid_entry = false; } if( valid_entry ) { m_HomeRangeIsRelative = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["AllowGhostTriggering"] ); } catch { valid_entry = false; } if( valid_entry ) { m_AllowGhostTriggering = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["AllowNPCTriggering"] ); } catch { valid_entry = false; } if( valid_entry ) { m_AllowNPCTriggering = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["SpawnOnTrigger"] ); } catch { valid_entry = false; } if( valid_entry ) { m_SpawnOnTrigger = boolEntry; } valid_entry = true; try { boolEntry = bool.Parse( (string)dr["SmartSpawning"] ); } catch { valid_entry = false; } if( valid_entry ) { m_SmartSpawning = boolEntry; } valid_entry = true; try { strEntry = (string)dr["RegionName"]; } catch { valid_entry = false; } if( valid_entry ) { RegionName = strEntry; } valid_entry = true; try { strEntry = (string)dr["PlayerPropertyName"]; } catch { valid_entry = false; } if( valid_entry ) { m_PlayerPropertyName = strEntry; } valid_entry = true; try { strEntry = (string)dr["MobPropertyName"]; } catch { valid_entry = false; } if( valid_entry ) { m_MobPropertyName = strEntry; } valid_entry = true; try { strEntry = (string)dr["MobTriggerName"]; } catch { valid_entry = false; } if( valid_entry ) { m_MobTriggerName = strEntry; } valid_entry = true; try { strEntry = (string)dr["ObjectPropertyName"]; } catch { valid_entry = false; } if( valid_entry ) { m_ObjectPropertyName = strEntry; } valid_entry = true; try { strEntry = (string)dr["ObjectPropertyItemName"]; } catch { valid_entry = false; } if( valid_entry ) { string[] typeargs = strEntry.Split( ",".ToCharArray(), 2 ); string typestr = null; string namestr = strEntry; if( typeargs.Length > 1 ) { namestr = typeargs[0]; typestr = typeargs[1]; } m_ObjectPropertyItem = BaseXmlSpawner.FindItemByName( this, namestr, typestr ); } valid_entry = true; try { strEntry = (string)dr["SetPropertyItemName"]; } catch { valid_entry = false; } if( valid_entry ) { string[] typeargs = strEntry.Split( ",".ToCharArray(), 2 ); string typestr = null; string namestr = strEntry; if( typeargs.Length > 1 ) { namestr = typeargs[0]; typestr = typeargs[1]; } m_SetPropertyItem = BaseXmlSpawner.FindItemByName( this, namestr, typestr ); } valid_entry = true; try { strEntry = (string)dr["Name"]; } catch { valid_entry = false; } if( valid_entry ) { Name = strEntry; } valid_entry = true; try { strEntry = (string)dr["Map"]; } catch { valid_entry = false; } if( valid_entry ) { // Convert the xml map value to a real map object try { Map = Map.Parse( strEntry ); } catch { } } // try loading the new spawn specifications first SpawnObject[] Spawns = new SpawnObject[0]; bool havenew = true; valid_entry = true; try { Spawns = SpawnObject.LoadSpawnObjectsFromString2( (string)dr["Objects2"] ); } catch { havenew = false; } if( !havenew ) { // try loading the new spawn specifications try { Spawns = SpawnObject.LoadSpawnObjectsFromString( (string)dr["Objects"] ); } catch { valid_entry = false; } // can only have one of these defined } if( valid_entry ) { // clear existing spawns RemoveSpawnObjects(); // Create the new array of spawned objects m_SpawnObjects = new ArrayList(); // Assign the list of objects to spawn SpawnObjects = Spawns; } } } } } }
public void configGamePlayer(PlayerClassType playerClassCongfig, int playerRefID, string playerName, SpawnObject spawn) { this.playerRefID = playerRefID; playerClass = playerClassCongfig.playerClass; if (this.playerClass == PlayerClassType.ClassList.GAME_MASTER) { GameSessionManager gameManager = this.gameObject.GetComponent<GameSessionManager>(); gameManager.scriptEnabled = true; } else { SpaceshipController spaceshipController = this.GetComponent<SpaceshipController>(); HealthSystem spaceshipHealth = this.GetComponent<HealthSystem>(); StealSystem spaceshipSteal = this.GetComponent<StealSystem>(); CombatSystem spaceshipCombat = this.GetComponent<CombatSystem>(); AbilitySystem abilitySystem = this.GetComponent<AbilitySystem>(); spaceshipController.PlayerName = playerName; spaceshipController.playerRefID = playerRefID; spaceshipController.scriptEnabled = true; spaceshipController.spriteName = playerClassCongfig.shipSprite.name; spaceshipController.transformScale = playerClassCongfig.transformScale; spaceshipController.colliderSize = playerClassCongfig.colliderSize; abilitySystem.config = playerClass; Debug.Log (spawn.location); spaceshipHealth.respawnLocation = spawn.location; spaceshipHealth.respawnRotation = spawn.rotation; spaceshipSteal.playerRefID = this.playerRefID; spaceshipSteal.playerName = playerName; if (spawnGamePrefabs) { if (planetPrefab != null && satellitePrefab != null && basePrefab != null) { planetReference = (GameObject)Instantiate(planetPrefab, transform.position + playerClassCongfig.planetOffset, transform.rotation); NetworkServer.Spawn(planetReference); SatelliteController satelliteControl = satellitePrefab.GetComponent<SatelliteController>(); HealthSystem satelliteHealth = satellitePrefab.GetComponent<HealthSystem>(); satelliteControl.orbitCentre = planetReference.transform.position; satelliteControl.playerRefID = this.playerRefID; satelliteHealth.respawnLocation = planetReference.transform.position + new Vector3(0,-satelliteControl.orbitRadius,0); satelliteReference = (GameObject)Instantiate(satellitePrefab, planetReference.transform.position, transform.rotation); NetworkServer.Spawn(satelliteReference); StealSystem baseSteal = basePrefab.GetComponent<StealSystem>(); baseSteal.playerRefID = this.playerRefID; baseReference = (GameObject)Instantiate(basePrefab, planetReference.transform.position + playerClassCongfig.baseOffset, transform.rotation); NetworkServer.Spawn(baseReference); } } } }
public void RefreshNextSpawnTime( SpawnObject so ) { if( so == null ) return; int mind = (int)(so.MinDelay * 60); int maxd = (int)(so.MaxDelay * 60); if( mind < 0 || maxd < 0 ) { so.NextSpawn = DateTime.Now; } else { TimeSpan delay = TimeSpan.FromSeconds( Utility.RandomMinMax( mind, maxd ) ); so.NextSpawn = DateTime.Now + delay; } }
public XmlSpawner( Guid uniqueId, int x, int y, int width, int height, string name, int maxCount, TimeSpan minDelay, TimeSpan maxDelay, TimeSpan duration, int proximityRange, int proximityTriggerSound, int amount, int team, int homeRange, bool isRelativeHomeRange, SpawnObject[] spawnObjects, TimeSpan minRefractory, TimeSpan maxRefractory, TimeSpan todstart, TimeSpan todend, Item objectPropertyItem, string objectPropertyName, string proximityMessage, string itemTriggerName, string noitemTriggerName, string speechTrigger, string mobTriggerName, string mobPropertyName, string playerPropertyName, double triggerProbability, Item setPropertyItem, bool isGroup, TODModeType todMode, int killReset, bool externalTriggering, int sequentialSpawning, string regionName, bool allowghost, bool allownpc, bool spawnontrigger, string configfile, TimeSpan despawnTime, string skillTrigger, bool smartSpawning, WayPoint wayPoint ) : base( BaseItemId ) { m_UniqueId = uniqueId.ToString(); InitSpawn( x, y, width, height, name, maxCount, minDelay, maxDelay, duration, proximityRange, proximityTriggerSound, amount, team, homeRange, isRelativeHomeRange, spawnObjects, minRefractory, maxRefractory, todstart, todend, objectPropertyItem, objectPropertyName, proximityMessage, itemTriggerName, noitemTriggerName, speechTrigger, mobTriggerName, mobPropertyName, playerPropertyName, triggerProbability, setPropertyItem, isGroup, todMode, killReset, externalTriggering, sequentialSpawning, regionName, allowghost, allownpc, spawnontrigger, configfile, despawnTime, skillTrigger, smartSpawning, wayPoint ); }
public void RemoveSpawnObjects( SpawnObject so ) { if( so == null ) return; Defrag( false ); ArrayList deletelist = new ArrayList(); for( int i = 0; i < so.SpawnedObjects.Count; ++i ) { object o = so.SpawnedObjects[i]; if( o is Item || o is Mobile ) deletelist.Add( o ); } DeleteFromList( deletelist ); // Defrag again Defrag( false ); }
public void RemoveSpawnObjects(SpawnObject so) { if (so == null) return; Defrag(false); for (int i = 0; i < so.SpawnedObjects.Count; ++i) { object o = so.SpawnedObjects[i]; if (o is Item) ((Item)o).Delete(); else if (o is Mobile) ((Mobile)o).Delete(); } // Defrag again Defrag(false); }
public static void XmlImportMap(string filename, Mobile from, out int processedmaps, out int processedspawners) { processedmaps = 0; processedspawners = 0; int total_processed_maps = 0; int total_processed_spawners = 0; if (filename == null || filename.Length <= 0 || from == null || from.Deleted) return; // Check if the file exists if (System.IO.File.Exists(filename) == true) { int spawnercount = 0; int badspawnercount = 0; int linenumber = 0; // default is no map override, use the map spec from each spawn line int overridemap = -1; try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader(filename)) { string line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { // format of each .map line is * Dragon:Wyvern 5209 965 -40 2 2 10 50 30 1 // * typename:typename:... x y z map mindelay maxdelay homerange spawnrange maxcount // or // * typename:typename:... x y z map mindelay maxdelay homerange spawnrange spawnid maxcount // ## are comments // overridemap mapnumber // map 0 is tram+fel // map 1 is fel // map 2 is tram // map 3 is ilsh // map 4 is mal // map 5 is tokuno linenumber++; string[] args = line.Trim().Split(' '); // look for the override keyword if (args.Length == 2 && (args[0].ToLower() == "overridemap")) { try { overridemap = int.Parse(args[1]); } catch { } } // look for a spawn spec line if (args.Length > 0 && (args[0] == "*")) { bool badspawn = false; int x = 0; int y = 0; int z = 0; int map = 0; int mindelay = 0; int maxdelay = 0; int homerange = 0; int spawnrange = 0; int maxcount = 0; int spawnid = 0; string[] typenames = null; if (args.Length != 11 && args.Length != 12) { badspawn = true; from.SendMessage("Invalid arg count {1} at line {0}", linenumber, args.Length); } else { // get the list of spawns typenames = args[1].Split(':'); // parse the rest of the args if (args.Length == 11) { try { x = int.Parse(args[2]); y = int.Parse(args[3]); z = int.Parse(args[4]); map = int.Parse(args[5]); mindelay = int.Parse(args[6]); maxdelay = int.Parse(args[7]); homerange = int.Parse(args[8]); spawnrange = int.Parse(args[9]); maxcount = int.Parse(args[10]); } catch { from.SendMessage("Parsing error at line {0}", linenumber); badspawn = true; } } else if (args.Length == 12) { try { x = int.Parse(args[2]); y = int.Parse(args[3]); z = int.Parse(args[4]); map = int.Parse(args[5]); mindelay = int.Parse(args[6]); maxdelay = int.Parse(args[7]); homerange = int.Parse(args[8]); spawnrange = int.Parse(args[9]); spawnid = int.Parse(args[10]); maxcount = int.Parse(args[11]); } catch { from.SendMessage("Parsing error at line {0}", linenumber); badspawn = true; } } } if (!badspawn && typenames != null && typenames.Length > 0) { // everything seems ok so go ahead and make the spawner // check for map override if (overridemap >= 0) map = overridemap; Map spawnmap = Map.Internal; switch (map) { case 0: spawnmap = Map.Felucca; // note it also does trammel break; case 1: spawnmap = Map.Felucca; break; case 2: spawnmap = Map.Trammel; break; case 3: spawnmap = Map.Ilshenar; break; case 4: spawnmap = Map.Malas; break; case 5: try { spawnmap = Map.Parse("Tokuno"); } catch { from.SendMessage("Invalid map at line {0}", linenumber); } break; } if (!IsValidMapLocation(x, y, spawnmap)) { // invalid so dont spawn it badspawnercount++; from.SendMessage("Invalid map/location at line {0}", linenumber); from.SendMessage("Bad spawn at line {1}: {0}", line, linenumber); continue; } // allow it to make an xmlspawner instead // first add all of the creatures on the list SpawnObject[] so = new SpawnObject[typenames.Length]; bool hasvendor = true; for (int i = 0; i < typenames.Length; i++) { so[i] = new SpawnObject(typenames[i], maxcount); // check the type to see if there are vendors on it Type type = SpawnerType.GetType(typenames[i]); // check for vendor-only spawners which get special spawnrange treatment if (type != null && (type != typeof(BaseVendor) && !type.IsSubclassOf(typeof(BaseVendor)))) { hasvendor = false; } } // assign it a unique id Guid SpawnId = Guid.NewGuid(); // and give it a name based on the spawner count and file string spawnername = String.Format("{0}#{1}", filename, spawnercount); // Create the new xml spawner XmlSpawner spawner = new XmlSpawner(SpawnId, x, y, 0, 0, spawnername, maxcount, TimeSpan.FromMinutes(mindelay), TimeSpan.FromMinutes(maxdelay), TimeSpan.FromMinutes(0), -1, defaultTriggerSound, 1, 0, homerange, false, so, TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), null, null, null, null, null, null, null, null, null, 1, null, false, defTODMode, defKillReset, false, -1, null, false, false, false, null, TimeSpan.FromHours(0), null, false, null); if (hasvendor) { // force vendor spawners to behave like the distro spawner.SpawnRange = 0; } else { spawner.SpawnRange = spawnrange; } spawner.m_PlayerCreated = true; string fromname = null; if (from != null) fromname = from.Name; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; spawner.MoveToWorld(new Point3D(x, y, z), spawnmap); if (spawner.Map == Map.Internal) { badspawnercount++; spawner.Delete(); from.SendMessage("Invalid map at line {0}", linenumber); from.SendMessage("Bad spawn at line {1}: {0}", line, linenumber); continue; } spawnercount++; // handle the special case of map 0 that also needs to do trammel if (map == 0) { spawnmap = Map.Trammel; // assign it a unique id SpawnId = Guid.NewGuid(); // Create the new xml spawner spawner = new XmlSpawner(SpawnId, x, y, 0, 0, spawnername, maxcount, TimeSpan.FromMinutes(mindelay), TimeSpan.FromMinutes(maxdelay), TimeSpan.FromMinutes(0), -1, defaultTriggerSound, 1, 0, homerange, false, so, TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), null, null, null, null, null, null, null, null, null, 1, null, false, defTODMode, defKillReset, false, -1, null, false, false, false, null, TimeSpan.FromHours(0), null, false, null); spawner.SpawnRange = spawnrange; spawner.m_PlayerCreated = true; spawner.LastModifiedBy = fromname; spawner.FirstModifiedBy = fromname; spawner.MoveToWorld(new Point3D(x, y, z), spawnmap); if (spawner.Map == Map.Internal) { badspawnercount++; spawner.Delete(); from.SendMessage("Bad spawn at line {1}: {0}", line, linenumber); continue; } spawnercount++; } } else { badspawnercount++; from.SendMessage("Bad spawn at line {1}: {0}", line, linenumber); } } } sr.Close(); } } catch (Exception e) { // Let the user know what went wrong. from.SendMessage("The file could not be read: {0}", e.Message); } from.SendMessage("Imported {0} spawners from {1}", spawnercount, filename); from.SendMessage("{0} bad spawners detected", badspawnercount); processedmaps = 1; processedspawners = spawnercount; } else // check to see if it is a directory if (System.IO.Directory.Exists(filename) == true) { // if so then import all of the .map files in the directory string[] files = null; try { files = Directory.GetFiles(filename, "*.map"); } catch { } if (files != null && files.Length > 0) { from.SendMessage("Importing {0} .map files from directory {1}", files.Length, filename); foreach (string file in files) { XmlImportMap(file, from, out processedmaps, out processedspawners); total_processed_maps += processedmaps; total_processed_spawners += processedspawners; } } // recursively search subdirectories for more .map files string[] dirs = null; try { dirs = Directory.GetDirectories(filename); } catch { } if (dirs != null && dirs.Length > 0) { foreach (string dir in dirs) { XmlImportMap(dir, from, out processedmaps, out processedspawners); total_processed_maps += processedmaps; total_processed_spawners += processedspawners; } } from.SendMessage("Imported a total of {0} .map files and {2} spawners from directory {1}", total_processed_maps, filename, total_processed_spawners); processedmaps = total_processed_maps; processedspawners = total_processed_spawners; } else { from.SendMessage("{0} does not exist", filename); } }
public override void SpawnEntity() { Ttl = 9999999; Level.AddEntity(this); var addEntity = new SpawnObject(Shooter.Wrapper) { EntityId = EntityId, X = KnownPosition.X, Y = KnownPosition.Y, Z = KnownPosition.Z, Type = ObjectType, Info = Shooter.EntityId, Pitch = (byte) KnownPosition.Pitch, Yaw = (byte) KnownPosition.Yaw, VelocityX = (short)Velocity.X, VelocityY = (short)Velocity.Y, VelocityZ = (short)Velocity.Z, }; Level.BroadcastPacket(addEntity); }
public static void XmlLoadFromStream( Stream fs, string filename, string SpawnerPrefix, Mobile from, Point3D fromloc, Map frommap, bool loadrelative, int maxrange, bool loadnew, out int processedmaps, out int processedspawners, bool verbose ) { processedmaps = 0; processedspawners = 0; if( fs == null ) return; // assign an id that will be used to distinguish the newly loaded spawners by appending it to their name Guid newloadid = Guid.NewGuid(); int TotalCount = 0; int TrammelCount = 0; int FeluccaCount = 0; int IlshenarCount = 0; int MalasCount = 0; int TokunoCount = 0; int OtherCount = 0; bool questionable_spawner = false; bool bad_spawner = false; int badcount = 0; int questionablecount = 0; int failedobjectitemcount = 0; int failedsetitemcount = 0; int relativex = -1; int relativey = -1; int relativez = 0; Map relativemap = null; if( from != null ) from.SendMessage( string.Format( "Loading {0} objects{1} from file {2}.", "XmlSpawner", ((SpawnerPrefix != null && SpawnerPrefix.Length > 0) ? " beginning with " + SpawnerPrefix : string.Empty), filename ) ); // Create the data set DataSet ds = new DataSet( SpawnDataSetName ); // Read in the file bool fileerror = false; try { ds.ReadXml( fs ); } catch { if( from != null ) from.SendMessage( 33, "Error reading xml file {0}", filename ); fileerror = true; } // close the file fs.Close(); if( fileerror ) return; // Check that at least a single table was loaded if( ds.Tables != null && ds.Tables.Count > 0 ) { // Add each spawn point to the current map if( ds.Tables[SpawnTablePointName] != null && ds.Tables[SpawnTablePointName].Rows.Count > 0 ) foreach( DataRow dr in ds.Tables[SpawnTablePointName].Rows ) { // load in the spawner info. Certain fields are required and therefore cannot be ignored // the exception handler for those will flag bad_spawner and the result will be logged // Each row makes up a single spawner string SpawnName = "Spawner"; try { SpawnName = (string)dr["Name"]; } catch { questionable_spawner = true; } if( loadnew ) { // append the new id to the name SpawnName = String.Format( "{0}-{1}", SpawnName, newloadid ); } // Check if there is any spawner name criteria specified on the load if( (SpawnerPrefix == null) || (SpawnerPrefix.Length == 0) || (SpawnName.StartsWith( SpawnerPrefix ) == true) ) { // Try load the GUID (might not work so create a new GUID) Guid SpawnId = Guid.NewGuid(); if( !loadnew ) { try { SpawnId = new Guid( (string)dr["UniqueId"] ); } catch { } } else { // change the dataset guid to the newly created one when new loading try { dr["UniqueId"] = SpawnId; } catch { Console.WriteLine( "unable to set UniqueId" ); } } int SpawnCentreX = fromloc.X; int SpawnCentreY = fromloc.Y; int SpawnCentreZ = fromloc.Z; try { SpawnCentreX = int.Parse( (string)dr["CentreX"] ); } catch { bad_spawner = true; } try { SpawnCentreY = int.Parse( (string)dr["CentreY"] ); } catch { bad_spawner = true; } try { SpawnCentreZ = int.Parse( (string)dr["CentreZ"] ); } catch { bad_spawner = true; } int SpawnX = SpawnCentreX; int SpawnY = SpawnCentreY; int SpawnWidth = 0; int SpawnHeight = 0; try { SpawnX = int.Parse( (string)dr["X"] ); } catch { questionable_spawner = true; } try { SpawnY = int.Parse( (string)dr["Y"] ); } catch { questionable_spawner = true; } try { SpawnWidth = int.Parse( (string)dr["Width"] ); } catch { questionable_spawner = true; } try { SpawnHeight = int.Parse( (string)dr["Height"] ); } catch { questionable_spawner = true; } // Try load the InContainer (default to false) bool InContainer = false; int ContainerX = 0; int ContainerY = 0; int ContainerZ = 0; try { InContainer = bool.Parse( (string)dr["InContainer"] ); } catch { } if( InContainer ) { try { ContainerX = int.Parse( (string)dr["ContainerX"] ); } catch { } try { ContainerY = int.Parse( (string)dr["ContainerY"] ); } catch { } try { ContainerZ = int.Parse( (string)dr["ContainerZ"] ); } catch { } } // Get the map (default to the mobiles map) if the relative distance is too great, then use the defined map Map SpawnMap = frommap; string XmlMapName = frommap.Name; //if(!loadrelative && !loadnew) { // Try to get the "map" field, but in case it doesn't exist, catch and discard the exception try { XmlMapName = (string)dr["Map"]; } catch { questionable_spawner = true; } // Convert the xml map value to a real map object if( string.Compare( XmlMapName, Map.Trammel.Name, true ) == 0 || XmlMapName == "Trammel" ) { SpawnMap = Map.Trammel; TrammelCount++; } else if( string.Compare( XmlMapName, Map.Felucca.Name, true ) == 0 || XmlMapName == "Felucca" ) { SpawnMap = Map.Felucca; FeluccaCount++; } else if( string.Compare( XmlMapName, Map.Ilshenar.Name, true ) == 0 || XmlMapName == "Ilshenar" ) { SpawnMap = Map.Ilshenar; IlshenarCount++; } else if( string.Compare( XmlMapName, Map.Malas.Name, true ) == 0 || XmlMapName == "Malas" ) { SpawnMap = Map.Malas; MalasCount++; } else if( string.Compare( XmlMapName, Map.Tokuno.Name, true ) == 0 || XmlMapName == "Tokuno" ) { SpawnMap = Map.Tokuno; TokunoCount++; } else { try { SpawnMap = Map.Parse( XmlMapName ); } catch { } OtherCount++; } } // test to see whether the distance between the relative center point and the spawner is too great. If so then dont do relative if( relativex == -1 && relativey == -1 ) { // the first xml entry in the file will determine the origin relativex = SpawnCentreX; relativey = SpawnCentreY; relativez = SpawnCentreZ; // and also the relative map to relocate from relativemap = SpawnMap; } int SpawnRelZ = 0; int OrigZ = SpawnCentreZ; if( loadrelative && (Math.Abs( relativex - SpawnCentreX ) <= maxrange) && (Math.Abs( relativey - SpawnCentreY ) <= maxrange) && (SpawnMap == relativemap) ) { // its within range so shift it SpawnCentreX -= relativex - fromloc.X; SpawnCentreY -= relativey - fromloc.Y; SpawnX -= relativex - fromloc.X; SpawnY -= relativey - fromloc.Y; // force it to autosearch for Z when it places it but hold onto relative Z info just in case it can be placed there SpawnRelZ = relativez - fromloc.Z; SpawnCentreZ = short.MinValue; } // if relative loading has been specified, see if the loaded map is the same as the relativemap and relocate. // if it doesnt match then just leave it if( loadrelative && (relativemap == SpawnMap) ) { SpawnMap = frommap; } if( SpawnMap == Map.Internal ) bad_spawner = true; // Try load the IsRelativeHomeRange (default to true) bool SpawnIsRelativeHomeRange = true; try { SpawnIsRelativeHomeRange = bool.Parse( (string)dr["IsHomeRangeRelative"] ); } catch { } int SpawnHomeRange = 5; try { SpawnHomeRange = int.Parse( (string)dr["Range"] ); } catch { questionable_spawner = true; } int SpawnMaxCount = 1; try { SpawnMaxCount = int.Parse( (string)dr["MaxCount"] ); } catch { questionable_spawner = true; } //deal with double format for delay. default is the old minute format bool delay_in_sec = false; try { delay_in_sec = bool.Parse( (string)dr["DelayInSec"] ); } catch { } TimeSpan SpawnMinDelay = TimeSpan.FromMinutes( 5 ); TimeSpan SpawnMaxDelay = TimeSpan.FromMinutes( 10 ); if( delay_in_sec ) { try { SpawnMinDelay = TimeSpan.FromSeconds( int.Parse( (string)dr["MinDelay"] ) ); } catch { } try { SpawnMaxDelay = TimeSpan.FromSeconds( int.Parse( (string)dr["MaxDelay"] ) ); } catch { } } else { try { SpawnMinDelay = TimeSpan.FromMinutes( int.Parse( (string)dr["MinDelay"] ) ); } catch { } try { SpawnMaxDelay = TimeSpan.FromMinutes( int.Parse( (string)dr["MaxDelay"] ) ); } catch { } } TimeSpan SpawnMinRefractory = TimeSpan.FromMinutes( 0 ); try { SpawnMinRefractory = TimeSpan.FromMinutes( double.Parse( (string)dr["MinRefractory"] ) ); } catch { } TimeSpan SpawnMaxRefractory = TimeSpan.FromMinutes( 0 ); try { SpawnMaxRefractory = TimeSpan.FromMinutes( double.Parse( (string)dr["MaxRefractory"] ) ); } catch { } TimeSpan SpawnTODStart = TimeSpan.FromMinutes( 0 ); try { SpawnTODStart = TimeSpan.FromMinutes( double.Parse( (string)dr["TODStart"] ) ); } catch { } TimeSpan SpawnTODEnd = TimeSpan.FromMinutes( 0 ); try { SpawnTODEnd = TimeSpan.FromMinutes( double.Parse( (string)dr["TODEnd"] ) ); } catch { } int todmode = (int)TODModeType.Realtime; TODModeType SpawnTODMode = TODModeType.Realtime; try { todmode = int.Parse( (string)dr["TODMode"] ); } catch { } switch( (int)todmode ) { case (int)TODModeType.Gametime: SpawnTODMode = TODModeType.Gametime; break; case (int)TODModeType.Realtime: SpawnTODMode = TODModeType.Realtime; break; } int SpawnKillReset = defKillReset; try { SpawnKillReset = int.Parse( (string)dr["KillReset"] ); } catch { } string SpawnProximityMessage = null; // proximity message try { SpawnProximityMessage = (string)dr["ProximityTriggerMessage"]; } catch { } string SpawnItemTriggerName = null; try { SpawnItemTriggerName = (string)dr["ItemTriggerName"]; } catch { } string SpawnNoItemTriggerName = null; try { SpawnNoItemTriggerName = (string)dr["NoItemTriggerName"]; } catch { } string SpawnSpeechTrigger = null; try { SpawnSpeechTrigger = (string)dr["SpeechTrigger"]; } catch { } string SpawnSkillTrigger = null; try { SpawnSkillTrigger = (string)dr["SkillTrigger"]; } catch { } string SpawnMobTriggerName = null; try { SpawnMobTriggerName = (string)dr["MobTriggerName"]; } catch { } string SpawnMobPropertyName = null; try { SpawnMobPropertyName = (string)dr["MobPropertyName"]; } catch { } string SpawnPlayerPropertyName = null; try { SpawnPlayerPropertyName = (string)dr["PlayerPropertyName"]; } catch { } double SpawnTriggerProbability = 1; try { SpawnTriggerProbability = double.Parse( (string)dr["TriggerProbability"] ); } catch { } int SpawnSequentialSpawning = -1; try { SpawnSequentialSpawning = int.Parse( (string)dr["SequentialSpawning"] ); } catch { } string SpawnRegionName = null; try { SpawnRegionName = (string)dr["RegionName"]; } catch { } string SpawnConfigFile = null; try { SpawnConfigFile = (string)dr["ConfigFile"]; } catch { } bool SpawnAllowGhost = false; try { SpawnAllowGhost = bool.Parse( (string)dr["AllowGhostTriggering"] ); } catch { } bool SpawnAllowNPC = false; try { SpawnAllowNPC = bool.Parse( (string)dr["AllowNPCTriggering"] ); } catch { } bool SpawnSpawnOnTrigger = false; try { SpawnSpawnOnTrigger = bool.Parse( (string)dr["SpawnOnTrigger"] ); } catch { } bool SpawnSmartSpawning = false; try { SpawnSmartSpawning = bool.Parse( (string)dr["SmartSpawning"] ); } catch { } string SpawnObjectPropertyName = null; try { SpawnObjectPropertyName = (string)dr["ObjectPropertyName"]; } catch { } // read in the object proximity target, this will be an object name, so have to do a search // to find the item in the world. Also have to test for redundancy string triggerObjectName = null; try { triggerObjectName = (string)dr["ObjectPropertyItemName"]; } catch { } // read in the target for the set command, this will be an object name, so have to do a search // to find the item in the world. Also have to test for redundancy string setObjectName = null; try { setObjectName = (string)dr["SetPropertyItemName"]; } catch { } // we will assign this during the self-reference resolution pass Item SpawnSetPropertyItem = null; // we will assign this during the self-reference resolution pass Item SpawnObjectPropertyItem = null; // read the duration parameter from the xml file // but older files wont have it so deal with that condition and set it to the default of "0", i.e. infinite duration // Try to get the "Duration" field, but in case it doesn't exist, catch and discard the exception TimeSpan SpawnDuration = TimeSpan.FromMinutes( 0 ); try { SpawnDuration = TimeSpan.FromMinutes( double.Parse( (string)dr["Duration"] ) ); } catch { } TimeSpan SpawnDespawnTime = TimeSpan.FromHours( 0 ); try { SpawnDespawnTime = TimeSpan.FromHours( double.Parse( (string)dr["DespawnTime"] ) ); } catch { } int SpawnProximityRange = -1; // Try to get the "ProximityRange" field, but in case it doesn't exist, catch and discard the exception try { SpawnProximityRange = int.Parse( (string)dr["ProximityRange"] ); } catch { } int SpawnProximityTriggerSound = 0; // Try to get the "ProximityTriggerSound" field, but in case it doesn't exist, catch and discard the exception try { SpawnProximityTriggerSound = int.Parse( (string)dr["ProximityTriggerSound"] ); } catch { } int SpawnAmount = 1; try { SpawnAmount = int.Parse( (string)dr["Amount"] ); } catch { } bool SpawnExternalTriggering = false; try { SpawnExternalTriggering = bool.Parse( (string)dr["ExternalTriggering"] ); } catch { } string waypointstr = null; try { waypointstr = (string)dr["Waypoint"]; } catch { } WayPoint SpawnWaypoint = GetWaypoint( waypointstr ); int SpawnTeam = 0; try { SpawnTeam = int.Parse( (string)dr["Team"] ); } catch { questionable_spawner = true; } bool SpawnIsGroup = false; try { SpawnIsGroup = bool.Parse( (string)dr["IsGroup"] ); } catch { questionable_spawner = true; } bool SpawnIsRunning = false; try { SpawnIsRunning = bool.Parse( (string)dr["IsRunning"] ); } catch { questionable_spawner = true; } // try loading the new spawn specifications first SpawnObject[] Spawns = new SpawnObject[0]; bool havenew = true; try { Spawns = SpawnObject.LoadSpawnObjectsFromString2( (string)dr["Objects2"] ); } catch { havenew = false; } if( !havenew ) { // try loading the new spawn specifications try { Spawns = SpawnObject.LoadSpawnObjectsFromString( (string)dr["Objects"] ); } catch { questionable_spawner = true; } // can only have one of these defined } // do a check on the location of the spawner if( !IsValidMapLocation( SpawnCentreX, SpawnCentreY, SpawnMap ) ) { if( from != null ) from.SendMessage( 33, "Invalid location '{0}' at [{1} {2}] in {3}", SpawnName, SpawnCentreX, SpawnCentreY, XmlMapName ); bad_spawner = true; } // Check if this spawner already exists XmlSpawner OldSpawner = null; bool found_container = false; bool found_spawner = false; Container spawn_container = null; if( !bad_spawner ) { foreach( Item i in World.Items.Values ) { if( i is XmlSpawner ) { XmlSpawner CheckXmlSpawner = (XmlSpawner)i; // Check if the spawners GUID is the same as the one being loaded // and that the spawners map is the same as the one being loaded if( (CheckXmlSpawner.UniqueId == SpawnId.ToString()) /* && ( CheckXmlSpawner.Map == SpawnMap || loadrelative)*/ ) { OldSpawner = (XmlSpawner)i; found_spawner = true; } } //look for containers with the spawn coordinates if the incontainer flag is set if( InContainer && !found_container && (i is Container) && (SpawnCentreX == i.Location.X) && (SpawnCentreY == i.Location.Y) && (SpawnCentreZ == i.Location.Z || SpawnCentreZ == short.MinValue) ) { // assume this is the container that the spawner was in found_container = true; spawn_container = i as Container; } // ok we can break if we have handled both the spawner and any containers if( found_spawner && (found_container || !InContainer) ) break; } } // test to see whether the spawner specification was valid, bad, or questionable if( bad_spawner ) { badcount++; if( from != null ) from.SendMessage( 33, "Invalid spawner" ); // log it long fileposition = -1; try { fileposition = fs.Position; } catch { } try { using( StreamWriter op = new StreamWriter( "badxml.log", true ) ) { op.WriteLine( "# Invalid spawner : {0}: Fileposition {1} {2}", DateTime.Now, fileposition, filename ); op.WriteLine(); } } catch { } } else if( questionable_spawner ) { questionablecount++; if( from != null ) from.SendMessage( 33, "Questionable spawner '{0}' at [{1} {2}] in {3}", SpawnName, SpawnCentreX, SpawnCentreY, XmlMapName ); // log it long fileposition = -1; try { fileposition = fs.Position; } catch { } try { using( StreamWriter op = new StreamWriter( "badxml.log", true ) ) { op.WriteLine( "# Questionable spawner : {0}: Format: X Y Z Map SpawnerName Fileposition Xmlfile", DateTime.Now ); op.WriteLine( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", SpawnCentreX, SpawnCentreY, SpawnCentreZ, XmlMapName, SpawnName, fileposition, filename ); op.WriteLine(); } } catch { } } if( !bad_spawner ) { // Delete the old spawner if it exists if( OldSpawner != null ) OldSpawner.Delete(); // Create the new spawner XmlSpawner TheSpawn = new XmlSpawner( SpawnId, SpawnX, SpawnY, SpawnWidth, SpawnHeight, SpawnName, SpawnMaxCount, SpawnMinDelay, SpawnMaxDelay, SpawnDuration, SpawnProximityRange, SpawnProximityTriggerSound, SpawnAmount, SpawnTeam, SpawnHomeRange, SpawnIsRelativeHomeRange, Spawns, SpawnMinRefractory, SpawnMaxRefractory, SpawnTODStart, SpawnTODEnd, SpawnObjectPropertyItem, SpawnObjectPropertyName, SpawnProximityMessage, SpawnItemTriggerName, SpawnNoItemTriggerName, SpawnSpeechTrigger, SpawnMobTriggerName, SpawnMobPropertyName, SpawnPlayerPropertyName, SpawnTriggerProbability, SpawnSetPropertyItem, SpawnIsGroup, SpawnTODMode, SpawnKillReset, SpawnExternalTriggering, SpawnSequentialSpawning, SpawnRegionName, SpawnAllowGhost, SpawnAllowNPC, SpawnSpawnOnTrigger, SpawnConfigFile, SpawnDespawnTime, SpawnSkillTrigger, SpawnSmartSpawning, SpawnWaypoint ); //TheSpawn.Group = SpawnIsGroup;\ string fromname = null; if( from != null ) fromname = from.Name; TheSpawn.LastModifiedBy = fromname; TheSpawn.FirstModifiedBy = fromname; // Try to find a valid Z height if required (SpawnCentreZ = short.MinValue) int NewZ = 0; // Check if relative loading is set. If so then try loading at the z-offset position first with no surface requirement, then try auto /*if(loadrelative && SpawnMap.CanFit( SpawnCentreX, SpawnCentreY, OrigZ - SpawnRelZ, SpawnFitSize,true, false,false )) */ if( loadrelative && HasTileSurface( SpawnMap, SpawnCentreX, SpawnCentreY, OrigZ - SpawnRelZ ) ) { NewZ = OrigZ - SpawnRelZ; } else if( SpawnCentreZ == short.MinValue ) { NewZ = SpawnMap.GetAverageZ( SpawnCentreX, SpawnCentreY ); if( SpawnMap.CanFit( SpawnCentreX, SpawnCentreY, NewZ, SpawnFitSize ) == false ) { for( int x = 1; x <= 39; x++ ) { if( SpawnMap.CanFit( SpawnCentreX, SpawnCentreY, NewZ + x, SpawnFitSize ) ) { NewZ += x; break; } } } } else { // This spawn point already has a defined Z location, so use it NewZ = SpawnCentreZ; } // if this is a container held spawner, drop it in the container if( found_container && (spawn_container != null) && !spawn_container.Deleted ) { TheSpawn.Location = (new Point3D( ContainerX, ContainerY, ContainerZ )); spawn_container.AddItem( TheSpawn ); } else { // disable the X_Y adjustments in OnLocationChange IgnoreLocationChange = true; TheSpawn.MoveToWorld( new Point3D( SpawnCentreX, SpawnCentreY, NewZ ), SpawnMap ); } // reset the spawner TheSpawn.Reset(); TheSpawn.Running = SpawnIsRunning; // update subgroup-specific next spawn times TheSpawn.NextSpawn = TimeSpan.Zero; TheSpawn.ResetNextSpawnTimes(); // Send a message to the client that the spawner is created if( from != null && verbose ) from.SendMessage( 188, "Created '{0}' in {1} at {2}", TheSpawn.Name, TheSpawn.Map.Name, TheSpawn.Location.ToString() ); // Do a total respawn //TheSpawn.Respawn(); // Increment the count TotalCount++; } bad_spawner = false; questionable_spawner = false; } } if( from != null ) from.SendMessage( "Resolving spawner self references" ); if( ds.Tables[SpawnTablePointName] != null && ds.Tables[SpawnTablePointName].Rows.Count > 0 ) foreach( DataRow dr in ds.Tables[SpawnTablePointName].Rows ) { // Try load the GUID bool badid = false; Guid SpawnId = Guid.NewGuid(); try { SpawnId = new Guid( (string)dr["UniqueId"] ); } catch { badid = true; } if( badid ) continue; // Get the map Map SpawnMap = frommap; string XmlMapName = frommap.Name; if( !loadrelative ) { try { XmlMapName = (string)dr["Map"]; } catch { } // Convert the xml map value to a real map object try { SpawnMap = Map.Parse( XmlMapName ); } catch { } } bool found_spawner = false; XmlSpawner OldSpawner = null; foreach( Item i in World.Items.Values ) { if( i is XmlSpawner ) { XmlSpawner CheckXmlSpawner = (XmlSpawner)i; // Check if the spawners GUID is the same as the one being loaded // and that the spawners map is the same as the one being loaded if( (CheckXmlSpawner.UniqueId == SpawnId.ToString()) /* && ( CheckXmlSpawner.Map == SpawnMap || loadrelative) */) { OldSpawner = (XmlSpawner)i; found_spawner = true; } } if( found_spawner ) break; } if( found_spawner && OldSpawner != null && !OldSpawner.Deleted ) { // resolve item name references since they may have referred to spawners that were just created string setObjectName = null; try { setObjectName = (string)dr["SetPropertyItemName"]; } catch { } if( setObjectName != null && setObjectName.Length > 0 ) { // try to parse out the type information if it has also been saved string[] typeargs = setObjectName.Split( ",".ToCharArray(), 2 ); string typestr = null; string namestr = setObjectName; if( typeargs.Length > 1 ) { namestr = typeargs[0]; typestr = typeargs[1]; } // if this is a new load then assume that it will be referring to another newly loaded object so append the newloadid if( loadnew ) { string tmpsetObjectName = String.Format( "{0}-{1}", namestr, newloadid ); OldSpawner.m_SetPropertyItem = BaseXmlSpawner.FindItemByName( null, tmpsetObjectName, typestr ); } // if this fails then try the original if( OldSpawner.m_SetPropertyItem == null ) { OldSpawner.m_SetPropertyItem = BaseXmlSpawner.FindItemByName( null, namestr, typestr ); } if( OldSpawner.m_SetPropertyItem == null ) { failedsetitemcount++; if( from != null ) from.SendMessage( 33, "Failed to initialize SetItemProperty Object '{0}' on ' '{1}' at [{2} {3}] in {4}", setObjectName, OldSpawner.Name, OldSpawner.Location.X, OldSpawner.Location.Y, OldSpawner.Map ); // log it try { using( StreamWriter op = new StreamWriter( "badxml.log", true ) ) { op.WriteLine( "# Failed SetItemProperty Object initialization : {0}: Format: ObjectName X Y Z Map SpawnerName Xmlfile", DateTime.Now ); op.WriteLine( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", setObjectName, OldSpawner.Location.X, OldSpawner.Location.Y, OldSpawner.Location.Z, OldSpawner.Map, OldSpawner.Name, filename ); op.WriteLine(); } } catch { } } } string triggerObjectName = null; try { triggerObjectName = (string)dr["ObjectPropertyItemName"]; } catch { } if( triggerObjectName != null && triggerObjectName.Length > 0 ) { string[] typeargs = triggerObjectName.Split( ",".ToCharArray(), 2 ); string typestr = null; string namestr = triggerObjectName; if( typeargs.Length > 1 ) { namestr = typeargs[0]; typestr = typeargs[1]; } // if this is a new load then assume that it will be referring to another newly loaded object so append the newloadid if( loadnew ) { string tmptriggerObjectName = String.Format( "{0}-{1}", namestr, newloadid ); OldSpawner.m_ObjectPropertyItem = BaseXmlSpawner.FindItemByName( null, tmptriggerObjectName, typestr ); } // if this fails then try the original if( OldSpawner.m_ObjectPropertyItem == null ) { OldSpawner.m_ObjectPropertyItem = BaseXmlSpawner.FindItemByName( null, namestr, typestr ); } if( OldSpawner.m_ObjectPropertyItem == null ) { failedobjectitemcount++; if( from != null ) from.SendMessage( 33, "Failed to initialize TriggerObject '{0}' on ' '{1}' at [{2} {3}] in {4}", triggerObjectName, OldSpawner.Name, OldSpawner.Location.X, OldSpawner.Location.Y, OldSpawner.Map ); // log it try { using( StreamWriter op = new StreamWriter( "badxml.log", true ) ) { op.WriteLine( "# Failed TriggerObject initialization : {0}: Format: ObjectName X Y Z Map SpawnerName Xmlfile", DateTime.Now ); op.WriteLine( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", triggerObjectName, OldSpawner.Location.X, OldSpawner.Location.Y, OldSpawner.Location.Z, OldSpawner.Map, OldSpawner.Name, filename ); op.WriteLine(); } } catch { } } } } } } // close the file try { fs.Close(); } catch { } if( from != null ) from.SendMessage( "{0} spawner(s) were created from file {1} [Trammel={2}, Felucca={3}, Ilshenar={4}, Malas={5}, Tokuno={6} Other={7}].", TotalCount, filename, TrammelCount, FeluccaCount, IlshenarCount, MalasCount, TokunoCount, OtherCount ); if( failedobjectitemcount > 0 ) { if( from != null ) from.SendMessage( 33, "Failed to initialize TriggerObjects in {0} spawners. Saved to 'badxml.log'", failedobjectitemcount ); } if( failedsetitemcount > 0 ) { if( from != null ) from.SendMessage( 33, "Failed to initialize SetItemProperty Objects in {0} spawners. Saved to 'badxml.log'", failedsetitemcount ); } if( badcount > 0 ) { if( from != null ) from.SendMessage( 33, "{0} bad spawners detected. Saved to 'badxml.log'", badcount ); } if( questionablecount > 0 ) { if( from != null ) from.SendMessage( 33, "{0} questionable spawners detected. Saved to 'badxml.log'", questionablecount ); } processedmaps = 1; processedspawners = TotalCount; }
public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = reader.ReadInt(); bool haveproximityrange = false; bool hasnewobjectinfo = false; int tmpSpawnListSize = 0; ArrayList tmpSubGroup = null; ArrayList tmpSequentialResetTime = null; ArrayList tmpSequentialResetTo = null; ArrayList tmpKillsNeeded = null; ArrayList tmpRequireSurface = null; ArrayList tmpRestrictKillsToSubgroup = null; ArrayList tmpClearOnAdvance = null; ArrayList tmpMinDelay = null; ArrayList tmpMaxDelay = null; ArrayList tmpNextSpawn = null; ArrayList tmpDisableSpawn = null; ArrayList tmpPackRange = null; ArrayList tmpSpawnsPer = null; switch( version ) { case 30: { m_AllowNPCTriggering = reader.ReadBool(); goto case 29; } case 29: { tmpSpawnListSize = reader.ReadInt(); tmpSpawnsPer = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { int spawnsper = reader.ReadInt(); tmpSpawnsPer.Add( spawnsper ); } goto case 28; } case 28: { if( version < 29 ) tmpSpawnListSize = reader.ReadInt(); tmpPackRange = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { int packrange = reader.ReadInt(); tmpPackRange.Add( packrange ); } goto case 27; } case 27: { if( version < 28 ) tmpSpawnListSize = reader.ReadInt(); tmpDisableSpawn = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { bool disablespawn = reader.ReadBool(); tmpDisableSpawn.Add( disablespawn ); } goto case 26; } case 26: { m_SpawnOnTrigger = reader.ReadBool(); m_FirstModified = reader.ReadDateTime(); m_LastModified = reader.ReadDateTime(); goto case 25; } case 25: { goto case 24; } case 24: { if( version < 27 ) tmpSpawnListSize = reader.ReadInt(); tmpRestrictKillsToSubgroup = new ArrayList( tmpSpawnListSize ); tmpClearOnAdvance = new ArrayList( tmpSpawnListSize ); tmpMinDelay = new ArrayList( tmpSpawnListSize ); tmpMaxDelay = new ArrayList( tmpSpawnListSize ); tmpNextSpawn = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { bool restrictkills = reader.ReadBool(); bool clearadvance = reader.ReadBool(); double mind = reader.ReadDouble(); double maxd = reader.ReadDouble(); DateTime nextspawn = reader.ReadDeltaTime(); tmpRestrictKillsToSubgroup.Add( restrictkills ); tmpClearOnAdvance.Add( clearadvance ); tmpMinDelay.Add( mind ); tmpMaxDelay.Add( maxd ); tmpNextSpawn.Add( nextspawn ); } bool hasitems = reader.ReadBool(); if( hasitems ) { m_ShowBoundsItems = reader.ReadItemList(); } goto case 23; } case 23: { IsInactivated = reader.ReadBool(); SmartSpawning = reader.ReadBool(); goto case 22; } case 22: { SkillTrigger = reader.ReadString(); // note this will also register the skill m_skill_that_triggered = (SkillName)reader.ReadInt(); m_FreeRun = reader.ReadBool(); m_mob_who_triggered = reader.ReadMobile(); goto case 21; } case 21: { m_DespawnTime = reader.ReadTimeSpan(); goto case 20; } case 20: { if( version < 24 ) tmpSpawnListSize = reader.ReadInt(); tmpRequireSurface = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { bool requiresurface = reader.ReadBool(); tmpRequireSurface.Add( requiresurface ); } goto case 19; } case 19: { m_ConfigFile = reader.ReadString(); m_OnHold = reader.ReadBool(); m_HoldSequence = reader.ReadBool(); m_FirstModifiedBy = reader.ReadString(); m_LastModifiedBy = reader.ReadString(); // deserialize the keyword tag list int tagcount = reader.ReadInt(); m_KeywordTagList = new ArrayList( tagcount ); for( int i = 0; i < tagcount; i++ ) { BaseXmlSpawner.KeywordTag tag = new BaseXmlSpawner.KeywordTag( null, this ); tag.Deserialize( reader ); } goto case 18; } case 18: { m_AllowGhostTriggering = reader.ReadBool(); goto case 17; } case 17: { if( version < 25 ) { // the textentrybooks are deleted on deserialization so no need to track them reader.ReadItem(); } goto case 16; } case 16: { hasnewobjectinfo = true; m_SequentialSpawning = reader.ReadInt(); TimeSpan seqdelay = reader.ReadTimeSpan(); m_SeqEnd = DateTime.Now + seqdelay; if( version < 20 ) { tmpSpawnListSize = reader.ReadInt(); } tmpSubGroup = new ArrayList( tmpSpawnListSize ); tmpSequentialResetTime = new ArrayList( tmpSpawnListSize ); tmpSequentialResetTo = new ArrayList( tmpSpawnListSize ); tmpKillsNeeded = new ArrayList( tmpSpawnListSize ); for( int i = 0; i < tmpSpawnListSize; ++i ) { int subgroup = reader.ReadInt(); double resettime = reader.ReadDouble(); int resetto = reader.ReadInt(); int killsneeded = reader.ReadInt(); tmpSubGroup.Add( subgroup ); tmpSequentialResetTime.Add( resettime ); tmpSequentialResetTo.Add( resetto ); tmpKillsNeeded.Add( killsneeded ); } m_RegionName = reader.ReadString(); // 2004.02.08 :: Omega Red goto case 15; } case 15: { m_ExternalTriggering = reader.ReadBool(); m_ExternalTrigger = reader.ReadBool(); goto case 14; } case 14: { m_NoItemTriggerName = reader.ReadString(); goto case 13; } case 13: { m_GumpState = reader.ReadString(); goto case 12; } case 12: { int todtype = reader.ReadInt(); switch( todtype ) { case (int)TODModeType.Gametime: m_TODMode = TODModeType.Gametime; break; case (int)TODModeType.Realtime: m_TODMode = TODModeType.Realtime; break; } goto case 11; } case 11: { m_KillReset = reader.ReadInt(); m_skipped = reader.ReadBool(); m_spawncheck = reader.ReadInt(); goto case 10; } case 10: { m_SetPropertyItem = reader.ReadItem(); goto case 9; } case 9: { m_TriggerProbability = reader.ReadDouble(); goto case 8; } case 8: { m_MobPropertyName = reader.ReadString(); m_MobTriggerName = reader.ReadString(); m_PlayerPropertyName = reader.ReadString(); goto case 7; } case 7: { m_SpeechTrigger = reader.ReadString(); goto case 6; } case 6: { m_ItemTriggerName = reader.ReadString(); goto case 5; } case 5: { m_ProximityTriggerMessage = reader.ReadString(); m_ObjectPropertyItem = reader.ReadItem(); m_ObjectPropertyName = reader.ReadString(); m_killcount = reader.ReadInt(); goto case 4; } case 4: { haveproximityrange = true; m_ProximityRange = reader.ReadInt(); m_ProximityTriggerSound = reader.ReadInt(); m_proximityActivated = reader.ReadBool(); m_durActivated = reader.ReadBool(); m_refractActivated = reader.ReadBool(); m_StackAmount = reader.ReadInt(); m_TODStart = reader.ReadTimeSpan(); m_TODEnd = reader.ReadTimeSpan(); m_MinRefractory = reader.ReadTimeSpan(); m_MaxRefractory = reader.ReadTimeSpan(); if( m_refractActivated == true ) { TimeSpan delay = reader.ReadTimeSpan(); DoTimer3( delay ); } if( m_durActivated == true ) { TimeSpan delay = reader.ReadTimeSpan(); DoTimer2( delay ); } goto case 3; } case 3: { m_ShowContainerStatic = reader.ReadItem() as Static; goto case 2; } case 2: { m_Duration = reader.ReadTimeSpan(); goto case 1; } case 1: { m_UniqueId = reader.ReadString(); m_HomeRangeIsRelative = reader.ReadBool(); goto case 0; } case 0: { m_Name = reader.ReadString(); // backward compatibility with old name storage if( m_Name != null && m_Name != String.Empty ) Name = m_Name; m_X = reader.ReadInt(); m_Y = reader.ReadInt(); m_Width = reader.ReadInt(); m_Height = reader.ReadInt(); if( m_Width == m_Height ) m_SpawnRange = m_Width / 2; else m_SpawnRange = -1; if( !haveproximityrange ) { m_ProximityRange = -1; } m_WayPoint = reader.ReadItem() as WayPoint; m_Group = reader.ReadBool(); m_MinDelay = reader.ReadTimeSpan(); m_MaxDelay = reader.ReadTimeSpan(); m_Count = reader.ReadInt(); m_Team = reader.ReadInt(); m_HomeRange = reader.ReadInt(); m_Running = reader.ReadBool(); if( m_Running == true ) { TimeSpan delay = reader.ReadTimeSpan(); DoTimer( delay ); } // Read in the size of the spawn object list int SpawnListSize = reader.ReadInt(); m_SpawnObjects = new ArrayList( SpawnListSize ); for( int i = 0; i < SpawnListSize; ++i ) { string TypeName = reader.ReadString(); int TypeMaxCount = reader.ReadInt(); SpawnObject TheSpawnObject = new SpawnObject( TypeName, TypeMaxCount ); m_SpawnObjects.Add( TheSpawnObject ); string typeName = BaseXmlSpawner.ParseObjectType( TypeName ); // does it have a substitution that might change its validity? // if so then let it go if( typeName == null || ((SpawnerType.GetType( typeName ) == null) && (!BaseXmlSpawner.IsTypeOrItemKeyword( typeName ) && typeName.IndexOf( '{' ) == -1 && !typeName.StartsWith( "*" ) && !typeName.StartsWith( "#" ))) ) { if( m_WarnTimer == null ) m_WarnTimer = new WarnTimer2(); m_WarnTimer.Add( Location, Map, TypeName ); this.status_str = "invalid type: " + typeName; } // Read in the number of spawns already int SpawnedCount = reader.ReadInt(); TheSpawnObject.SpawnedObjects = new ArrayList( SpawnedCount ); for( int x = 0; x < SpawnedCount; ++x ) { int serial = reader.ReadInt(); if( serial < -1 ) { // minusone is reserved for unknown types by default // minustwo on is used for referencing keyword tags int tagserial = -1 * (serial + 2); // get the tag with that serial and add it BaseXmlSpawner.KeywordTag t = BaseXmlSpawner.GetFromTagList( this, tagserial ); if( t != null ) { TheSpawnObject.SpawnedObjects.Add( t ); } } else { IEntity e = World.FindEntity( serial ); if( e != null ) TheSpawnObject.SpawnedObjects.Add( e ); } } } // now have to reintegrate the later version spawnobject information into the earlier version desered objects if( hasnewobjectinfo && tmpSpawnListSize == SpawnListSize ) { for( int i = 0; i < SpawnListSize; ++i ) { SpawnObject so = (SpawnObject)m_SpawnObjects[i]; so.SubGroup = (int)tmpSubGroup[i]; so.SequentialResetTime = (double)tmpSequentialResetTime[i]; so.SequentialResetTo = (int)tmpSequentialResetTo[i]; so.KillsNeeded = (int)tmpKillsNeeded[i]; if( version > 19 ) so.RequireSurface = (bool)tmpRequireSurface[i]; bool restrictkills = false; bool clearadvance = true; double mind = -1; double maxd = -1; DateTime nextspawn = DateTime.MinValue; if( version > 23 ) { restrictkills = (bool)tmpRestrictKillsToSubgroup[i]; clearadvance = (bool)tmpClearOnAdvance[i]; mind = (double)tmpMinDelay[i]; maxd = (double)tmpMaxDelay[i]; nextspawn = (DateTime)tmpNextSpawn[i]; } so.RestrictKillsToSubgroup = restrictkills; so.ClearOnAdvance = clearadvance; so.MinDelay = mind; so.MaxDelay = maxd; so.NextSpawn = nextspawn; bool disablespawn = false; if( version > 26 ) { disablespawn = (bool)tmpDisableSpawn[i]; } so.Disabled = disablespawn; int packrange = -1; if( version > 27 ) { packrange = (int)tmpPackRange[i]; } so.PackRange = packrange; int spawnsper = 1; if( version > 28 ) { spawnsper = (int)tmpSpawnsPer[i]; } so.SpawnsPerTick = spawnsper; } } break; } } }
public XmlSpawner( string creatureName ) : base( BaseItemId ) { m_PlayerCreated = true; m_UniqueId = Guid.NewGuid().ToString(); SpawnObject[] so = new SpawnObject[1]; so[0] = new SpawnObject( creatureName, 1 ); SpawnRange = defSpawnRange; InitSpawn( 0, 0, m_Width, m_Height, string.Empty, 1, defMinDelay, defMaxDelay, defDuration, defProximityRange, defProximityTriggerSound, defAmount, defTeam, defHomeRange, defRelativeHome, so, defMinRefractory, defMaxRefractory, defTODStart, defTODEnd, null, null, null, null, null, null, null, null, null, defTriggerProbability, null, defIsGroup, defTODMode, defKillReset, false, -1, null, false, false, false, null, defDespawnTime, null, false, null ); }
internal static SpawnObject[] LoadSpawnObjectsFromString( string ObjectList ) { // Clear the spawn object list ArrayList NewSpawnObjects = new ArrayList(); if( ObjectList != null && ObjectList.Length > 0 ) { // Split the string based on the object separator first ':' string[] SpawnObjectList = ObjectList.Split( ':' ); // Parse each item in the array foreach( string s in SpawnObjectList ) { // Split the single spawn object item by the max count '=' string[] SpawnObjectDetails = s.Split( '=' ); // Should be two entries if( SpawnObjectDetails.Length == 2 ) { // Validate the information // Make sure the spawn object name part has a valid length if( SpawnObjectDetails[0].Length > 0 ) { // Make sure the max count part has a valid length if( SpawnObjectDetails[1].Length > 0 ) { int maxCount = 1; try { maxCount = int.Parse( SpawnObjectDetails[1] ); } catch( System.Exception ) { // Something went wrong, leave the default amount } } // Create the spawn object and store it in the array list SpawnObject so = new SpawnObject( SpawnObjectDetails[0], maxCount ); NewSpawnObjects.Add( so ); } } } } } return (SpawnObject[])NewSpawnObjects.ToArray( typeof( SpawnObject ) ); }
public void InitSpawn( int x, int y, int width, int height, string name, int maxCount, TimeSpan minDelay, TimeSpan maxDelay, TimeSpan duration, int proximityRange, int proximityTriggerSound, int amount, int team, int homeRange, bool isRelativeHomeRange, SpawnObject[] objectsToSpawn, TimeSpan minRefractory, TimeSpan maxRefractory, TimeSpan todstart, TimeSpan todend, Item objectPropertyItem, string objectPropertyName, string proximityMessage, string itemTriggerName, string noitemTriggerName, string speechTrigger, string mobTriggerName, string mobPropertyName, string playerPropertyName, double triggerProbability, Item setPropertyItem, bool isGroup, TODModeType todMode, int killReset, bool externalTriggering, int sequentialSpawning, string regionName, bool allowghost, bool allownpc, bool spawnontrigger, string configfile, TimeSpan despawnTime, string skillTrigger, bool smartSpawning, WayPoint wayPoint ) { Visible = false; Movable = false; m_X = x; m_Y = y; m_Width = width; m_Height = height; // init spawn range if compatible if( width == height ) m_SpawnRange = width / 2; else m_SpawnRange = -1; m_Running = true; m_Group = isGroup; if( (name != null) && (name.Length > 0) ) Name = name; else Name = "Spawner"; m_MinDelay = minDelay; m_MaxDelay = maxDelay; // duration and proximity range parameter m_MinRefractory = minRefractory; m_MaxRefractory = maxRefractory; m_TODStart = todstart; m_TODEnd = todend; m_TODMode = todMode; m_KillReset = killReset; m_Duration = duration; m_DespawnTime = despawnTime; m_ProximityRange = proximityRange; m_ProximityTriggerSound = proximityTriggerSound; m_proximityActivated = false; m_durActivated = false; m_refractActivated = false; m_Count = maxCount; m_Team = team; m_StackAmount = amount; m_HomeRange = homeRange; m_HomeRangeIsRelative = isRelativeHomeRange; m_ObjectPropertyItem = objectPropertyItem; m_ObjectPropertyName = objectPropertyName; m_ProximityTriggerMessage = proximityMessage; m_ItemTriggerName = itemTriggerName; m_NoItemTriggerName = noitemTriggerName; m_SpeechTrigger = speechTrigger; SkillTrigger = skillTrigger; // note this will register the skill as well m_MobTriggerName = mobTriggerName; m_MobPropertyName = mobPropertyName; m_PlayerPropertyName = playerPropertyName; m_TriggerProbability = triggerProbability; m_SetPropertyItem = setPropertyItem; m_ExternalTriggering = externalTriggering; m_ExternalTrigger = false; m_SequentialSpawning = sequentialSpawning; RegionName = regionName; m_AllowGhostTriggering = allowghost; m_AllowNPCTriggering = allownpc; m_SpawnOnTrigger = spawnontrigger; m_SmartSpawning = smartSpawning; ConfigFile = configfile; m_WayPoint = wayPoint; // set the totalitem property to -1 so that it doesnt show up in the item count of containers //TotalItems = -1; //UpdateTotal(this, TotalType.Items, -1); // Create the array of spawned objects m_SpawnObjects = new ArrayList(); // Assign the list of objects to spawn SpawnObjects = objectsToSpawn; // Kick off the process DoTimer( TimeSpan.FromSeconds( 1 ) ); }
internal static SpawnObject[] LoadSpawnObjectsFromString2( string ObjectList ) { // Clear the spawn object list ArrayList NewSpawnObjects = new ArrayList(); // spawn object definitions will take the form typestring:MX=int:SB=int:RT=double:TO=int:KL=int // or typestring:MX=int:SB=int:RT=double:TO=int:KL=int:OBJ=typestring... if( ObjectList != null && ObjectList.Length > 0 ) { string[] SpawnObjectList = BaseXmlSpawner.SplitString( ObjectList, ":OBJ=" ); // Parse each item in the array foreach( string s in SpawnObjectList ) { // at this point each spawn string will take the form typestring:MX=int:SB=int:RT=double:TO=int:KL=int // Split the single spawn object item by the max count to get the typename and the remaining parms string[] SpawnObjectDetails = BaseXmlSpawner.SplitString( s, ":MX=" ); // Should be two entries if( SpawnObjectDetails.Length == 2 ) { // Validate the information // Make sure the spawn object name part has a valid length if( SpawnObjectDetails[0].Length > 0 ) { // Make sure the parm part has a valid length if( SpawnObjectDetails[1].Length > 0 ) { // now parse out the parms // MaxCount string parmstr = GetParm( s, ":MX=" ); int maxCount = 1; try { maxCount = int.Parse( parmstr ); } catch { } // SubGroup parmstr = GetParm( s, ":SB=" ); int subGroup = 0; try { subGroup = int.Parse( parmstr ); } catch { } // SequentialSpawnResetTime parmstr = GetParm( s, ":RT=" ); double resetTime = 0; try { resetTime = double.Parse( parmstr ); } catch { } // SequentialSpawnResetTo parmstr = GetParm( s, ":TO=" ); int resetTo = 0; try { resetTo = int.Parse( parmstr ); } catch { } // KillsNeeded parmstr = GetParm( s, ":KL=" ); int killsNeeded = 0; try { killsNeeded = int.Parse( parmstr ); } catch { } // RestrictKills parmstr = GetParm( s, ":RK=" ); bool restrictKills = false; if( parmstr != null ) try { restrictKills = (int.Parse( parmstr ) == 1); } catch { } // ClearOnAdvance parmstr = GetParm( s, ":CA=" ); bool clearAdvance = true; // if kills needed is zero, then set CA to false by default. This maintains consistency with the // previous default behavior for old spawn specs that havent specified CA if( killsNeeded == 0 ) clearAdvance = false; if( parmstr != null ) try { clearAdvance = (int.Parse( parmstr ) == 1); } catch { } // MinDelay parmstr = GetParm( s, ":DN=" ); double minD = -1; try { minD = double.Parse( parmstr ); } catch { } // MaxDelay parmstr = GetParm( s, ":DX=" ); double maxD = -1; try { maxD = double.Parse( parmstr ); } catch { } // SpawnsPerTick parmstr = GetParm( s, ":SP=" ); int spawnsPer = 1; try { spawnsPer = int.Parse( parmstr ); } catch { } // PackRange parmstr = GetParm( s, ":PR=" ); int packRange = -1; try { packRange = int.Parse( parmstr ); } catch { } // Create the spawn object and store it in the array list SpawnObject so = new SpawnObject( SpawnObjectDetails[0], maxCount, subGroup, resetTime, resetTo, killsNeeded, restrictKills, clearAdvance, minD, maxD, spawnsPer, packRange ); NewSpawnObjects.Add( so ); } } } } } return (SpawnObject[])NewSpawnObjects.ToArray( typeof( SpawnObject ) ); }
public static void ExecuteAction(object attachedto, Mobile trigmob, string action) { Point3D loc = Point3D.Zero; Map map = null; if (attachedto is IEntity) { loc = ((IEntity)attachedto).Location; map = ((IEntity)attachedto).Map; } if (action == null || action.Length <= 0 || attachedto == null || map == null) { return; } string status_str = null; SpawnObject TheSpawn = new SpawnObject(null, 0); TheSpawn.TypeName = action; string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, attachedto, trigmob, action); string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName); if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName)) { BaseXmlSpawner.SpawnTypeKeyword( attachedto, TheSpawn, typeName, substitutedtypeName, true, trigmob, loc, map, out status_str); } else { // its a regular type descriptor so find out what it is Type type = SpawnerType.GetType(typeName); try { var arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/"); object o = CreateObject(type, arglist[0]); if (o == null) { status_str = "invalid type specification: " + arglist[0]; } else if (o is Mobile) { Mobile m = (Mobile)o; if (m is BaseCreature) { BaseCreature c = (BaseCreature)m; c.Home = loc; // Spawners location is the home point } m.Location = loc; m.Map = map; BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, m, trigmob, attachedto, out status_str); } else if (o is Item) { Item item = (Item)o; BaseXmlSpawner.AddSpawnItem( null, attachedto, TheSpawn, item, loc, map, trigmob, false, substitutedtypeName, out status_str); } } catch { } } }
public XmlSpawner( int amount, int minDelay, int maxDelay, int team, int homeRange, int spawnRange, string creatureName) : base(BaseItemId) { m_PlayerCreated = true; m_UniqueId = Guid.NewGuid().ToString(); SpawnRange = spawnRange; var so = new SpawnObject[1]; so[0] = new SpawnObject(creatureName, amount); InitSpawn( 0, 0, m_Width, m_Height, string.Empty, amount, TimeSpan.FromMinutes(minDelay), TimeSpan.FromMinutes(maxDelay), defDuration, defProximityRange, defProximityTriggerSound, defAmount, team, homeRange, defRelativeHome, so, defMinRefractory, defMaxRefractory, defTODStart, defTODEnd, null, null, null, null, null, null, null, null, null, defTriggerProbability, null, defIsGroup, defTODMode, defKillReset, false, -1, null, false, false, false, null, defDespawnTime, null, false, null); }