예제 #1
0
        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;
            }
        }
예제 #2
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);
        }