Click here to Skip to main content
15,887,821 members
Articles / Programming Languages / C#

Loot-Tables, Random Maps and Monsters - Part II

Rate me:
Please Sign up or sign in to vote.
4.92/5 (24 votes)
17 Jul 2012CPOL10 min read 51.6K   920   33  
Bringing RDS to life - How it all works.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using rds;

namespace rds_demo
{
	static class Demo2
	{
		public static void Run()
		{
			Console.WriteLine("*** DEMO 2 STARTED ***");
			Console.WriteLine("----------------------");

			RDSTable t = new RDSTable();

			RDSTable subtable1 = new RDSTable();
			RDSTable subtable2 = new RDSTable();
			RDSTable subtable3 = new RDSTable();

			t.AddEntry(subtable1, 10); // we add a table to a table thanks to the interfaces
			t.AddEntry(subtable2, 10);
			t.AddEntry(subtable3, 10);

			subtable1.AddEntry(new MyItem("Table 1 - Item 1"), 10);
			subtable1.AddEntry(new MyItem("Table 1 - Item 2"), 10);
			subtable1.AddEntry(new MyItem("Table 1 - Item 3"), 10);

			subtable2.AddEntry(new MyItem("Table 2 - Item 1"), 10);
			subtable2.AddEntry(new MyItem("Table 2 - Item 2"), 10);
			subtable2.AddEntry(new MyItem("Table 2 - Item 3"), 10);

			subtable3.AddEntry(new MyItem("Table 3 - Item 1"), 10);
			subtable3.AddEntry(new MyItem("Table 3 - Item 2"), 10);
			subtable3.AddEntry(new MyItem("Table 3 - Item 3"), 10);

			t.rdsCount = 3;

			// First demo: Simply loot 2 out of the 6
			Console.WriteLine("Step 1: Loot 3 items - 3 runs");
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine("Run {0}", i + 1);
				foreach (MyItem m in t.rdsResult)
					Console.WriteLine("    {0}", m);
			}

			// Set Table2 to be a unique drop (can be contained only once

			subtable2.rdsUnique = true;
			t.rdsCount = 10;

			Console.WriteLine("Step 2: Table 2 is now unique, loot 10 items - 3 runs");
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine("Run {0}", i + 1);
				foreach (MyItem m in t.rdsResult)
					Console.WriteLine("    {0}", m);
			}

			Console.WriteLine("-----------------------");
			Console.WriteLine("*** DEMO 2 COMPLETE ***");
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Austria Austria
Software Developer since the late 80's, grew up in the good old DOS-Era, switched to windows with Win95 and now doing .net since early 2002 (beta).
Long year c# experience in entertainment software, game programming, directX and XNA as well as SQLServer (DBA, Modelling, Optimizing, Replication, etc) and Oracle Databases in Enterprise environments. Started with Android development in 2014.

Developer of the gml-raptor platform (See my github profile below).

My Game Developer Profile at itch.io
My Repositories at github

Comments and Discussions