[AS3] Battle Arena (Multiplayer & Singleplayer)
Here is a guide for you, who use as3. This time i'll show you how to add a Battle Arena for you'r server that challenges you and your friends to survive against respawning monsters in a arena. Its is both possible to play co-operative or singleplayer Without further to do lets begin.
Note: During this tutorial you will experience a few errors, but dont mind as they will get fixed through the tutorial, as long you follow theese steps correctly, your arena will work at the end!
1 - Adding the Map
We start of by implementing our map. Look at the buttom of this file to find a download of my map, but you can make your own aswell, all it actually requires is walls and a spawn region.
2 - Adding the Map
Import you'r wmap and jm map file to: wServer>Realm>Worlds Click 1 time at the arena.wmap file, and set the build action to "Embedded Resource" (Look at image blow this)
3 - Adding the Map
Open RealmManager.cs, and add this:
Code:
AddWorld(World.ARENA, new BattleArena());
Below you'r latest world added. This could for an example be under:
Code:
AddWorld(World.GAUNTLET, new GauntletMap());
4 - Adding the Map
Now go to world.cs and add this:
Code:
public const int ARENA = -8;
NOTE: The number you see in the end of the code (-8 got to be the id after the map above. Here is an Example:
Try to find GAUNTLET = -7; As you see its id is 7, so if you have pasted the arena code below that the arenas id has to be 8 because thats the number after 7.
5 - Adding the Map
Go to UsePortalPacketHandler.cs, and add this:
Code:
case 0x0f69:
world = player.Manager.AddWorld(new BattleArena());
break;
Below this:
Code:
case 0x071f:
world = player.Manager.AddWorld(new GauntletMap());
break;
6 - Adding the Portal and the Key Key: Go to dat20.xml, and paste this code in the
Code:
<Object type="0x0f70" id="Battle Arena Key">
<Class>Equipment</Class>
<Item/>
<Texture>
<File>lofiObj3</File>
<Index>0xf4</Index>
</Texture>
<SlotType>10</SlotType>
<Description>Challenge your ability, in surviving against monsters in a trapped room.</Description>
<Sound>use_key</Sound>
<Consumable/>
<Soulbound/>
<Activate id="Battle Arena Portal">Create</Activate>
</Object>
Portal: Open dat19.xml, and paste this at the buttom:
7 - Adding Portal & Key to client
open you'r client source and do the same with the xmls. Note that the xml files in the client is called Dat files and they have different names. But don't worry just follow the steps below this.
Key: Open _y8.dat and paste in this at the buttom: Note: I suggest you rename _y8.dat to: dat20.dat, it will make it easier to remember the name.
Code:
<Object type="0x0f70" id="Battle Arena Key">
<Class>Equipment</Class>
<Item/>
<Texture>
<File>lofiObj3</File>
<Index>0xf4</Index>
</Texture>
<SlotType>10</SlotType>
<Description>Challenge your ability, in surviving against monsters in a trapped room.</Description>
<Sound>use_key</Sound>
<Consumable/>
<Soulbound/>
<Activate id="Battle Arena Portal">Create</Activate>
</Object>
Portal: Open _0H_y and paste in this at the buttom: Note: I suggest you rename _0H_y.dat to: dat19.dat, it will make it easier to remember the name.
Now we have the world added, but if you enter it, its just empty and nothing will happen. But no reasons to worry! We will add that now.
7 - Coding the Arena
Go to: wServer>Realm>Worlds. Right click on the "Worlds" folder and click "Add">"New Item.." Name the file: Arena.cs
8 - Coding the Arena
Replace everything in there with this:
Code:
using System;
using System.Collections.Generic;
using wServer.networking;
using wServer.networking.svrPackets;
using wServer.realm.terrain;
using wServer.realm.entities;
namespace wServer.realm.worlds
{
public class BattleArena : World
{
private bool ready = true;
private bool waiting;
public int wave = 1;
public List<string> Participants = new List<string>();
public BattleArena()
{
Id = ARENA;
Name = "Battle Arena";
Background = 1;
AllowTeleport = false;
// SetMusic("Arena");
// Blocking = true;
// Difficulty = 5;
}
protected override void Init()
{
base.FromWorldMap(typeof(RealmManager).Assembly.GetManifestResourceStream("wServer.realm.worlds.maps.Arena.wmap"));
}
public override World GetInstance(Client Client)
{
return Manager.AddWorld(new BattleArena());
}
private readonly string[] WeakEnemies =
{
"Flamer King", "Lair Skeleton King", "Native Fire Sprite", "Native Ice Sprite", "Native Magic Sprite", "Nomadic Shaman", "Ogre King", "Orc King", "Red Spider", "Sand Phantom",
"Swarm", "Tawny Warg", "Vampire Bat", "Wasp Queen", "Weretiger"
};
private readonly string[] NormalEnemies =
{
"Aberrant of Oryx", "Abomination of Oryx", "Adult White Dragon", "Assassin of Oryx", "Bile of Oryx", "Gigacorn",
"Great Lizard", "Minotaur", "Monstrosity of Oryx", "Phoenix Reborn", "Shambling Sludge", "Urgle"
};
private readonly string[] Gods =
{
"Beholder", "Ent God", "Flying Brain", "Djinn", "Ghost God", "Leviathan", "Medusa", "Slime God", "Sprite God", "White Demon"
};
private readonly string[] Bosses =
{
"Tomb Defender", "Tomb Attacker", "Tomb Support", "Arachna the Spider Queen", "Archdemon Malphas", "Crystal Prisoner", "Grand Sphinx", "Limon the Sprite God",
"Lord Ruthven", "Oryx the Mad God 1", "Septavius the Ghost God", "Stheno the Snake Queen", "Thessal the Mermaid Goddess"
};
public bool OutOfBounds(float x, float y)
{
if (Map.Height >= y && Map.Width >= x && x > -1 && y > 0)
return (Map[(int)x, (int)y].Region == TileRegion.Outside_Arena);
else
return true;
}
public override void Tick(RealmTime time)
{
base.Tick(time);
CheckOutOfBounds();
if (CheckPopulation())
{
if (ready)
{
if (waiting) return;
ready = false;
wave++;
foreach (KeyValuePair<int, Player> i in Players)
{
i.Value.Client.SendPacket(new NotificationPacket
{
Color = new ARGB(0xffff00ff),
ObjectId = i.Value.Id, //Can be disabled/enabled depending on solo/multiplayer
Text = "Wave " + wave.ToString() + " - Next round begins in: 5 Seconds"
});
}
waiting = true;
Timers.Add(new WorldTimer(5000, (world, t) =>
{
ready = false;
SpawnEnemies();
// SpawnBosses(); //Only activate every 10th round.
waiting = false;
}));
}
ready = true;
}
}
private void SpawnEnemies() //Spawn function, using wmap.pos.
{
try
{
List<string> enems = new List<string>();
Random r = new Random();
for (int i = 0; i < wave / 3 + 1; i++)
{
enems.Add(Gods[r.Next(0, Gods.Length)]);
}
for (int i = 0; i < wave / 3 + 1; i++)
{
enems.Add(NormalEnemies[r.Next(0, NormalEnemies.Length)]);
}
for (int i = 0; i < wave / 3 + 1; i++)
{
enems.Add(WeakEnemies[r.Next(0, WeakEnemies.Length)]);
}
Random r2 = new Random();
foreach (string i in enems)
{
ushort id = Manager.GameData.IdToObjectType[i];
int xloc = r2.Next(10, Map.Width) - 6;
int yloc = r2.Next(10, Map.Height) - 6;
Entity enemy = Entity.Resolve(Manager, id);
enemy.Move(xloc, yloc);
EnterWorld(enemy);
}
}
catch // (Exception ex)
{
// Log.Error(ex);
}
}
private void SpawnBosses()
{
List<string> enems = new List<string>();
Random r = new Random();
for (int i = 0; i < (1); i++)
{
enems.Add(Bosses[r.Next(0, Bosses.Length)]);
}
Random r2 = new Random();
foreach (string i in enems)
{
ushort id = Manager.GameData.IdToObjectType[i];
int xloc = r2.Next(10, Map.Width) - 6;
int yloc = r2.Next(10, Map.Height) - 6;
Entity enemy = Entity.Resolve(Manager, id);
enemy.Move(xloc, yloc);
EnterWorld(enemy);
}
}
private bool CheckPopulation()
{
if (Enemies.Count == 0)
{
return true;
}
return false;
}
private void CheckOutOfBounds()
{
foreach (KeyValuePair<int, Enemy> i in Enemies)
{
if (OutOfBounds(i.Value.X, i.Value.Y))
{
LeaveWorld(i.Value);
}
}
}
}
}
9 - Coding the Arena
Go to: Wmap.cs, and this:
Code:
Outside_Arena,
Below this:
Code:
Enemy,
And now you'r done. If you want to modify you'r arena difficulty and what the arena should spawn, you can always go into the BattleArena.cs file and change theese strings:
Code:
private readonly string[] WeakEnemies =
{
"Flamer King", "Lair Skeleton King", "Native Fire Sprite", "Native Ice Sprite", "Native Magic Sprite", "Nomadic Shaman", "Ogre King", "Orc King", "Red Spider", "Sand Phantom",
"Swarm", "Tawny Warg", "Vampire Bat", "Wasp Queen", "Weretiger"
};
private readonly string[] NormalEnemies =
{
"Aberrant of Oryx", "Abomination of Oryx", "Adult White Dragon", "Assassin of Oryx", "Bile of Oryx", "Gigacorn",
"Great Lizard", "Minotaur", "Monstrosity of Oryx", "Phoenix Reborn", "Shambling Sludge", "Urgle"
};
private readonly string[] Gods =
{
"Beholder", "Ent God", "Flying Brain", "Djinn", "Ghost God", "Leviathan", "Medusa", "Slime God", "Sprite God", "White Demon"
};
private readonly string[] Bosses =
{
"Tomb Defender", "Tomb Attacker", "Tomb Support", "Arachna the Spider Queen", "Archdemon Malphas", "Crystal Prisoner", "Grand Sphinx", "Limon the Sprite God",
"Lord Ruthven", "Oryx the Mad God 1", "Septavius the Ghost God", "Stheno the Snake Queen", "Thessal the Mermaid Goddess"
};
Wow thank you dud, i would've never expected you guys to actually give me another chance. Warms my heart. Me and artisan have made peace btw, so anyone thinking that the war is still going should know that it's not Thanks for the approvement luis
Wow thank you dud, i would've never expected you guys to actually give me another chance. Warms my heart. Me and artisan have made peace btw, so anyone thinking that the war is still going should know that it's not Thanks for the approvement luis