Questions regarding Smartfox
Posted: 03 Oct 2020, 18:13
Hi, so I am fairly new to SmartFox Server. I've been messing around with it off and on through out the years but never really settled on it. I am now attempting to learn it and Live Stream the development of a little prototype MMO. I was trying to figure out the best way to break everything up. I have experience with the HeroEngine and in Hero they have different types of "Areas" some are your normal zones/Game Areas but then they also break up all of the game features into areas. I got to think about that and looking into "Rooms" in Smartfox. I decided to attempt to break up game play features into different Rooms and then use the MMORooms for the actual zones.
So so far I have a MainWorld MMORoom and a Inventory Room which is just a regular basic room. When I join the MainWorld MMO Room I also join the Inventory Room at which point the Inventory Extension creates my Inventory. All of that is working fine. I am trying to figure out the best way to be able to access the Extensions from other extensions. So like the Inventory Extension would have to be accessed from the Combat Extension for example once a Mob is destroyed.
Just to test it out I decided to try and get a copy of the Inventory Extension from the Extension attached to the MainWorld room so I have a ServerReady event which contains the following:
When that event is called I get an exception:
I really don't get this. Granted I am not the best at Java but in C# that would have worked just fine. Yes in C# you would want some checks in there to make sure it is actually the type you are expecting it to be but in this case I know what extension is attached to the Inventory room and it should be the InventoryExtension.
So so far I have a MainWorld MMORoom and a Inventory Room which is just a regular basic room. When I join the MainWorld MMO Room I also join the Inventory Room at which point the Inventory Extension creates my Inventory. All of that is working fine. I am trying to figure out the best way to be able to access the Extensions from other extensions. So like the Inventory Extension would have to be accessed from the Combat Extension for example once a Mob is destroyed.
Just to test it out I decided to try and get a copy of the Inventory Extension from the Extension attached to the MainWorld room so I have a ServerReady event which contains the following:
Code: Select all
public class ServerReadyEvent extends BaseServerEventHandler
{
@Override
public void handleServerEvent(ISFSEvent isfse) throws SFSException {
Room InventoryRoom = getParentZone().getRoomByName("Inventory");
ISFSExtension ext = SmartFoxServer.getInstance().getExtensionManager().getRoomExtension(InventoryRoom);
InventoryExt = (InventoryExtension)ext;
trace("Setting Extension up!");
}
}
When that event is called I get an exception:
java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: MMOExtensions.InventoryExtension cannot be cast to MMOExtensions.InventoryExtension
Description: Error during event handling: java.lang.ClassCastException: MMOExtensions.InventoryExtension cannot be cast to MMOExtensions.InventoryExtension, Listener: { Ext: MMOExtension, Type: JAVA, Lev: ROOM, { Zone: BasicExamples }, [ MMORoom: MainWorld, Id: 1, Group: default, AOI: (25.0, 25.0, 25.0) ] }
+--- --- ---+
Stack Trace:
+--- --- ---+
MMOExtensions.WorldExtension$ServerReadyEvent.handleServerEvent(WorldExtension.java:42)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:259)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:769)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchGlobalEvent(SFSExtensionManager.java:670)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:638)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:885)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:66)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I really don't get this. Granted I am not the best at Java but in C# that would have worked just fine. Yes in C# you would want some checks in there to make sure it is actually the type you are expecting it to be but in this case I know what extension is attached to the Inventory room and it should be the InventoryExtension.