Esempio n. 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // Main Background
            mainBackground = Content.Load <Texture2D>("mainbg");
            // Loading Background
            loadingBackground = Content.Load <Texture2D>("loadingbg");
            // TODO: use this.Content to load your game content here
            // Initializing model bank which using for storing model file path
            modelBank = new GameModelBank(Content);
            // Initializing item bank which using for storing item data path
            itemBank = new GameItemBank(Content);
            // Load all model path here.
            Dictionary <short, GameModelConfig> modellist = config.getModelList();

            foreach (short id in modellist.Keys)
            {
                modelBank.Load(id, modellist[id]);
                // Cache
                GameModelNode cache = new GameModelNode(Content, modelBank);
                cache.Load(modelBank.getModelPath(id));
            }
            Dictionary <int, GameItemConfig> itemlist = config.getItemList();

            foreach (short id in itemlist.Keys)
            {
                itemBank.Load(id, itemlist[id]);
            }
            // Load all map
            Dictionary <short, GameMapConfig> maplist = config.getMapList();

            foreach (short id in maplist.Keys)
            {
                mapEntities.Add(id, new MapEntity(id, maplist[id], Content));
            }
            // Server configuration
            serverConfig = config.getServerList()[0];
            // Initializing game camera
            gameCamera = new GameCamera(graphics);
            // Particle system
            particle = new ParticlePreset(this, graphics, gameCamera);
            particle.LoadContent();
            // Game Event handler object
            gameHandler = new GameHandler(manager, network, this, Content, graphics, spriteBatch, modelBank, itemBank, classConfigs, gameCamera, audioSystem, particle);
            // Shadow map
            //shadow.LoadContent(spriteBatch, gameCamera);
            // Bloom post process
            bloom.Settings = BloomSettings.PresetSettings[0];
            // Way to go Effect
            wayToGoEffect = new GameModel(Content);
            wayToGoEffect.Load("waytogo");
            //Debug.WriteLine("LoadedContent");
        }
        public UnitEntity(int id, String name, GameClassConfig classcfg, int modelHair, int modelFace, int maxHP, int maxSP, GameMain game, ContentManager content, GraphicsDeviceManager graphics, SpriteBatch spriteBatch, SpriteFont charNameFont, SpriteFont charDamageFont, Texture2D whiteRect, GameModelBank modelBank, GameItemBank itemBank, AudioSystem audioSystem, ParticlePreset particleManager)
        {
            this.id             = id;
            name                = name.Replace("'58'", ":");
            name                = name.Replace("'59'", ";");
            name                = name.Replace("'32'", " ");
            name                = name.Replace("'39'", "'");
            this.name           = name;
            this.game           = game;
            this.content        = content;
            this.graphics       = graphics;
            this.spriteBatch    = spriteBatch;
            this.classcfg       = classcfg;
            this.modelBank      = modelBank;
            this.itemBank       = itemBank;
            this.charNameFont   = charNameFont;
            this.charDamageFont = charDamageFont;
            this.whiteRect      = whiteRect;
            short modelKey = classcfg.modelID;

            model = new GameModelNode(content, modelBank);
            model.Load(modelKey);
            model.Rotation = modelBank.getModelRotation(modelKey);
            model.Position = modelBank.getModelPosition(modelKey);
            model.Scale    = modelBank.getModelScale(modelKey);
            model.playClip((short)state, true);
            this.maxHP           = this.curHP = maxHP;
            this.maxSP           = this.curSP = maxSP;
            this.audioEmitter    = new AudioEmitter();
            this.audioSystem     = audioSystem;
            this.particleManager = particleManager;
            for (int i = 0; i < listDamageSize; ++i)
            {
                listDamageValue[i] = -1;
                listDamageTime[i]  = -1;
            }
        }
Esempio n. 3
0
 public void reset()
 {
     charEntity                  = null;
     SelectingCharacterID        = 0;
     currentSelectedClassModelID = -1;
 }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            //    this.Exit();

            // TODO: Add your update logic here
            ping();
            switch (state)
            {
            case GameState.game_login:
                switch (pageLogin.currentState())
                {
                case GameState.login_loggedin:
                    pageLogin.Visible = false;
                    pageCharacterSelector.init(pageLogin.getUserId());
                    pageCharacterSelector.Visible = true;
                    pageLogin.reset();
                    reset();
                    startPing = gameTime.ElapsedGameTime.Milliseconds;
                    state     = GameState.game_characterselector;
                    break;

                default:
                    break;
                }
                break;

            case GameState.game_characterselector:
                int selectcharid = pageCharacterSelector.getSelectingCharacterID();
                if (SelectingCharacterID != selectcharid && selectcharid > 0)
                {
                    SelectingCharacterID        = selectcharid;
                    currentSelectedClassModelID = classConfigs[pageCharacterSelector.getSelectedClassId()].modelID;
                    charEntity = new GameModelNode(Content, modelBank);
                    charEntity.Load(currentSelectedClassModelID);
                    charEntity.Rotation    = modelBank.getModelRotation(currentSelectedClassModelID);
                    charEntity.Rotation.Y += 90;
                    charEntity.Position    = modelBank.getModelPosition(currentSelectedClassModelID);
                    charEntity.Position.Y -= 7;
                    charEntity.Scale       = modelBank.getModelScale(currentSelectedClassModelID);
                    charEntity.playClip((short)GameState.anim_idle, true);
                }
                if (selectcharid <= 0)
                {
                    charEntity = null;
                }
                if (charEntity != null && currentSelectedClassModelID > -1)
                {
                    charEntity.Update(gameTime, Matrix.Identity);
                }
                switch (pageCharacterSelector.currentState())
                {
                case GameState.character_backtologin:
                    network.Send("LOGOUT:0;");
                    bool isLoggedOut = false;
                    while (!isLoggedOut && network.isConnected())
                    {
                        String responseLogoutMsg = "";
                        while (responseLogoutMsg.Length <= 0)
                        {
                            responseLogoutMsg = network.Receive();
                        }
                        String[] LogoutLine = responseLogoutMsg.Split(';');
                        for (int l = 0; l < LogoutLine.Length; ++l)
                        {
                            String[] LogoutMsg = LogoutLine[l].Split(':');
                            if (LogoutMsg[0].Equals("LOGOUT") && LogoutMsg.Length == 2)
                            {
                                isLoggedOut = true;
                                break;
                            }
                        }
                    }
                    network.Close();
                    pageCharacterSelector.Visible = false;
                    pageLogin.Visible             = true;
                    pageCharacterSelector.reset();
                    reset();
                    state = GameState.game_login;
                    break;

                case GameState.character_newcharacter:
                    pageCharacterSelector.Visible = false;
                    pageCharacterCreator.init(pageCharacterSelector.getUserId());
                    pageCharacterCreator.Visible = true;
                    pageCharacterSelector.reset();
                    reset();
                    state = GameState.game_charactercreator;
                    break;

                case GameState.character_selectedcharacter:
                    pageCharacterSelector.Visible = false;
                    gameHandler.init(pageCharacterSelector.getUserId(), pageCharacterSelector.getSelectedCharInfo());
                    pageCharacterSelector.reset();
                    reset();
                    state = GameState.game_map;
                    break;

                default:
                    break;
                }
                break;

            case GameState.game_charactercreator:
                short charclass_modelid = classConfigs[pageCharacterCreator.getSelectedClassId()].modelID;
                if (currentSelectedClassModelID != charclass_modelid)
                {
                    currentSelectedClassModelID = charclass_modelid;
                    charEntity = new GameModelNode(Content, modelBank);
                    charEntity.Load(currentSelectedClassModelID);
                    charEntity.Rotation    = modelBank.getModelRotation(currentSelectedClassModelID);
                    charEntity.Rotation.Y += 90;
                    charEntity.Position    = modelBank.getModelPosition(currentSelectedClassModelID);
                    charEntity.Position.Y -= 7;
                    charEntity.Scale       = modelBank.getModelScale(currentSelectedClassModelID);
                    charEntity.playClip((short)GameState.anim_idle, true);
                }
                if (charEntity != null && currentSelectedClassModelID > -1)
                {
                    charEntity.Update(gameTime, Matrix.Identity);
                }
                switch (pageCharacterCreator.currentState())
                {
                case GameState.character_newcharacterend:
                    pageCharacterCreator.Visible = false;
                    pageCharacterSelector.init(pageCharacterCreator.getUserId());
                    pageCharacterSelector.Visible = true;
                    pageCharacterCreator.reset();
                    reset();
                    state = GameState.game_characterselector;
                    break;

                default:
                    break;
                }
                break;

            case GameState.game_map:
                switch (gameHandler.currentState())
                {
                case GameState.map_warping:
                    gameHandler.initToWarp();
                    break;

                case GameState.map_warp:
                    cue.Stop(AudioStopOptions.Immediate);
                    gameHandler.warping();
                    short mapid = gameHandler.getCurrentMapID();
                    if (mapid > 0 && mapEntities.ContainsKey(mapid))
                    {
                        cue = audioSystem.getSoundBank().GetCue(mapEntities[mapid].getBGM());
                    }
                    cue.Play();
                    break;

                case GameState.map_backtologin:
                    network.Send("LOGOUT:0;");
                    bool isLoggedOut = false;
                    while (!isLoggedOut && network.isConnected())
                    {
                        String responseLogoutMsg = "";
                        while (responseLogoutMsg.Length <= 0)
                        {
                            responseLogoutMsg = network.Receive();
                        }
                        String[] LogoutLine = responseLogoutMsg.Split(';');
                        for (int l = 0; l < LogoutLine.Length; ++l)
                        {
                            String[] LogoutMsg = LogoutLine[l].Split(':');
                            if (LogoutMsg[0].Equals("LOGOUT") && LogoutMsg.Length == 2)
                            {
                                isLoggedOut = true;
                                break;
                            }
                        }
                    }
                    network.Close();
                    // Unload game connect
                    pageLogin.Visible          = true;
                    guiGameAttribute.Visible   = false;
                    guiGameChat.Visible        = false;
                    guiGameMenu.Visible        = false;
                    guiGameNPC.Visible         = false;
                    guiGameEnvironment.Visible = false;
                    guiGameInventory.Visible   = false;
                    guiGameInventory.clearInventoryData();
                    guiGameEquipment.Visible = false;
                    guiGameEquipment.clearEquipmentData();
                    cue.Stop(AudioStopOptions.Immediate);
                    cue = audioSystem.getSoundBank().GetCue("01");
                    cue.Play();
                    gameHandler.reset();
                    reset();
                    state = GameState.game_login;
                    break;

                case GameState.none:
                    gameHandler.ProcessKeyboard();
                    gameHandler.Update(gameTime, Matrix.Identity);
                    gameCamera.Update();
                    particle.Update(gameTime, 1);
                    if (IsActive)
                    {
                        gameCamera.ProcessMouse();
                        if (noCursorInsideWindows())
                        {
                            gameHandler.ProcessMouse();
                        }
                    }
                    //shadow.Update();
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
            audioSystem.update();
            base.Update(gameTime);
            manager.Update(gameTime);
        }