API:GameObjects

From WCell Wiki
Jump to: navigation, search

This article is related to development using the WCell API.

  • GameObjects are most of the static objects in the world that are not alive and (usually) interactable (such as doors, mines, herbs etc)
  • If you are interested into working with GameObjects (short: GO), you might want to start by considering the GO Dump (use dump gos in WCell.Tools)
  • Once you are familiar with the basics of GameObject-handling, you should take a look at the World API

Contents

GOMgr

  • The GOMgr is a public static class that contains all static (not changing) GO-related data after its been initialized
  • If WCell is setup to automatically load all content, the GOMgr will initialize at startup, else it will start loading after using the Load GOs command
  • GameObject-customizations require to be done at any point after the GOMgr has been initialized which means that you will need a public static method like this:
[Initialization]
[DependentInitialization(typeof(GOMgr))]
public static void InitGOs()
{
	// initialize my GOs here
}

GOEntry

  • Every GO in the world is built from a GOEntry which contains the definition of the specific GameObject
  • You can get GOEntry objects by using GOMgr.GetEntry(GOEntryId)
  • The Activated event is called when a new GameObject of the corresponding entry is added to the world
  • The Used event is called when a GameObject of that GOEntry is used by a given user

GameObjectHandler

  • All default GameObjects have a GameObjectType that is given by its GOEntry
  • Non-default GameObjects should have the Custom type
  • Every GO has an instance of GameObjectHandler which decides what to do when a GO is used
  • The GameObjectHandler depends on the GO's GameObjectType
  • All default handlers are defined in the GameObjects/Handlers folder
  • One can override default GO handling by assigning GOEntry.HandlerCreator to a custom kind of Handler
  • One can enforce creation of custom GameObjects by assigning GOEntry.GOCreator

GOTemplate

  • The GOTemplate class defines where to spawn a GO and some optional extra parameters
  • Every GOTemplates belongs to one specific GOEntry

Working with GameObjects

  • Ingame you can use the GO-command to add, select, delete and modify GameObjects
  • Type ingame: #? go

Example Code

  • Every time the door behind Rhakzor spawns, remember it (so we can open it later without having to search for it):
		[Initialization]
		[DependentInitialization(typeof(GOMgr))]
		public static void InitGOs()
		{
			var rhahkzorDoorEntry = GOMgr.GetEntry(GOEntryId.FactoryDoor);		// 13965

			if (rhahkzorDoorEntry != null)
			{
				rhahkzorDoorEntry.Activated += go =>
				{
					var instance = go.Region as Deadmines;
					if (instance != null && instance.rhahkzorDoor == null)
					{
						instance.rhahkzorDoor = go;
					}
				};
			}
  • When the cannon is used, destroy the door:
			var defiasCannonEntry = GOMgr.GetEntry(GOEntryId.DefiasCannon);

			defiasCannonEntry.Used += (cannon, user) =>
			{
				var door = cannon.GetNearbyGO(GOEntryId.IronCladDoor);
				if (door != null)
				{
					// destroy and delete
					door.State = GameObjectState.Destroyed;
					door.CallDelayed(5000, obj => obj.Delete());
					return true;
				}
				return false;
			};
Personal tools