public IGame CreateGame(string gameDir, GameMode mode, GameMap map) { MyTraceContext.ThreadTraceContext = new MyTraceContext("Server"); WorldTickMethod tickMethod; switch (mode) { case GameMode.Fortress: tickMethod = WorldTickMethod.Simultaneous; break; case GameMode.Adventure: tickMethod = WorldTickMethod.Sequential; break; default: throw new Exception(); } var world = new World(mode, tickMethod); Action<World> worldCreator; switch (map) { case GameMap.Fortress: worldCreator = Fortress.MountainWorldCreator.InitializeWorld; break; case GameMap.Adventure: var dwc = new Fortress.DungeonWorldCreator(world); worldCreator = dwc.InitializeWorld; break; case GameMap.Arena: throw new Exception(); default: throw new Exception(); } world.Initialize(delegate { worldCreator(world); }); var engine = new GameEngine(world, mode); InitGame(engine, gameDir); return engine; }
public Player(int userID, GameEngine engine) { this.UserID = userID; m_engine = engine; m_world = engine.World; m_seeAll = false; m_controllables = new List<LivingObject>(); Construct(); }
public IPRunner(World world, GameEngine engine, Player player) { m_player = player; m_scriptOutputStream = new MyStream(player.Send); m_scriptEngine = IronPython.Hosting.Python.CreateEngine(); InitRuntime(m_scriptEngine.Runtime); m_exprScope = m_scriptEngine.CreateScope(); InitScope(m_exprScope, world, engine, player); m_scriptScope = m_scriptEngine.CreateScope(); InitScope(m_scriptScope, world, engine, player); }
protected Player(int playerID, GameEngine engine) { // player ID 0 is invalid, 1 is reserved for server if (playerID == 0 || playerID == 1) throw new Exception(); this.PlayerID = playerID; m_engine = engine; m_world = engine.World; m_seeAll = ServerConfig.AllPlayersSeeAll; m_controllables = new List<LivingObject>(); Construct(); }
public User(IConnection connection, int userID, string name, GameEngine engine, bool isIronPythonEnabled) { m_connection = connection; this.UserID = userID; this.Name = name; m_engine = engine; trace.Header = String.Format("User({0}/{1})", this.Name, this.UserID); if (isIronPythonEnabled) { // XXX creating IP engine takes some time. Do it in the background. Race condition with IP msg handlers m_ipStartTask = Task.Run(() => { m_ipRunner = new IPRunner(this, m_engine); m_ipStartTask = null; }); } }
public IPRunner(User user, GameEngine engine) { m_user = user; m_scriptOutputStream = new MyStream(user.Send); m_scriptEngine = IronPython.Hosting.Python.CreateEngine(); InitRuntime(m_scriptEngine.Runtime); m_scopeVars = new Dictionary<string, object>() { { "engine", engine }, { "world", engine.World }, { "get", new Func<object, BaseObject>(engine.World.IPGet) }, }; m_exprScope = m_scriptEngine.CreateScope(m_scopeVars); InitScopeImports(m_exprScope); }
void InitGame(GameEngine engine, string gameDir) { IGameManager gameManager; switch (engine.GameMode) { case GameMode.Fortress: gameManager = new Fortress.FortressGameManager(engine.World); break; case GameMode.Adventure: gameManager = new Fortress.DungeonGameManager(engine.World); break; default: throw new Exception(); } engine.Init(gameDir, gameManager); }
void InitScope(ScriptScope scope, World world, GameEngine engine, Player player) { var globals = new Dictionary<string, object>() { { "world", world }, { "engine", engine }, { "player", player}, { "get", new Func<object, BaseObject>(world.IPGet) }, }; foreach (var kvp in globals) scope.SetVariable(kvp.Key, kvp.Value); // XXX perhaps this can also be done with C# somehow... m_scriptEngine.Execute("import Dwarrowdelf", scope); }