Inheritance: MonoBehaviour
Example #1
0
 public LoseState(DwarfGame game, GameStateManager stateManager, PlayState play)
     : base(game, "EconomyState", stateManager)
 {
     Input = new InputManager();
     PlayState = play;
     EnableScreensaver = false;
 }
Example #2
0
        public override void OnNext(GameStateManager value)
        {
            if (CurrentState == GameState.GamePause)
            {

            }
        }
    public void InitialState()
    {
        GameStateManager gameStateManager  = new GameStateManager();

        //Start at GameMenu
        Assert.That(gameStateManager.isGameStateEqual(gameStateManager.getGameMenuState()));
    }
Example #4
0
 public MainMenuState(DwarfGame game, GameStateManager stateManager)
     : base(game, "MainMenuState", stateManager)
 {
     ResourceLibrary library = new ResourceLibrary();
     IsGameRunning = false;
     MaintainState = false;
 }
 public StartState(GameStateManager gameManager)
 {
     manager = gameManager;
     manager.score = 0;
     manager.gameLevel = 1;
     manager.PlaySound(manager.bgm);
 }
 void Awake()
 {
     _fsm = new FSM<GameStates>();
     AddStates();
     AddTransitons();
     _instance = this;
 }
    // Update is called once per frame
    void Update()
    {
        if (GameObject.FindGameObjectsWithTag("MainObject").Length > 1)
        {
            GameObject[] list = GameObject.FindGameObjectsWithTag("MainObject");
            for (int i = 0; i < list.Length; ++i)
            {
                if (!list[i].GetComponent<GameStateManager>().objectSaved)
                    GameObject.Destroy(list[i]);

                else
                    gameStateManagerRef = list[i].GetComponent<GameStateManager>();
            }
        }

        if (gameStateManagerRef.GetScreenManager().GetCurrentScreenArea() != ScreenAreas.LevelComplete)
        {
            if (levelCompleteText)
            {
                levelCompleteText.GetComponent<GUIText>().enabled = false;
            }

            if (swipeToContinueText)
            {
                swipeToContinueText.GetComponent<GUIText>().enabled = false;
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        gameStateManagerRef = GameObject.FindGameObjectWithTag("MainObject").GetComponent<GameStateManager>();

        GameObject levelCompleteGUI = GameObject.FindGameObjectWithTag("EndLevelObject");
        GameObject blackFadeElement = GameObject.FindGameObjectWithTag("BlackFade");
        levelCompleteText = GameObject.FindGameObjectWithTag("LevelCompleteText");
        swipeToContinueText = GameObject.FindGameObjectWithTag("SwipeToContinueText");

        if (levelCompleteGUI)
        {
            levelCompleteGUI.GetComponent<GUITexture>().enabled = false;
            levelCompleteGUI.GetComponent<Camera>().enabled = false;
            levelCompleteGUI.GetComponent<GUILayer>().enabled = false;
        }

        if (blackFadeElement)
        {
            blackFadeElement.GetComponent<GUITexture>().enabled = false;
            blackFadeElement.GetComponent<Camera>().enabled = false;
            blackFadeElement.GetComponent<GUILayer>().enabled = false;
        }

        if (levelCompleteText)
        {
            levelCompleteText.GetComponent<GUIText>().enabled = false;
        }

        if (swipeToContinueText)
        {
            swipeToContinueText.GetComponent<GUIText>().enabled = false;
        }
    }
Example #9
0
        public void BuildLevel(ref GameStateManager gamestatemanager, string path)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(path);

            XPathNavigator navigator = xmlDocument.CreateNavigator();

            XPathExpression xpath = navigator.Compile("/Level/Structure/Layer");

            XPathNodeIterator iterator = navigator.Select(xpath);

            Dictionary<string, Queue<string>> dependencyMap = new Dictionary<string,Queue<string>>();

            try
            {
                while(iterator.MoveNext())
                {
                    XPathNavigator element = iterator.Current;
                    LoadLayer(element, ref dependencyMap);
                }
            }
            catch(XPathException xpe)
            {

            }
        }
Example #10
0
    // Use this for initialization
    void Start()
    {
        // Define state to name mapping for animations
        state_to_name.Add(0, "Idle");
        state_to_name.Add(1, "Walk");
        state_to_name.Add(2, "Charge");
        state_to_name.Add(3, "Grenade");
        state_to_name.Add(4, "Jump");
        state_to_name.Add(5, "Scared");
        state_to_name.Add(6, "Touch");
        state_to_name.Add(7, "Whisper");

        GameState = FindObjectOfType<GameStateManager>();

        if (GameState == null)
        {
            Debug.Log("GameStateManager missing! Abort!");
            this.enabled = false;
            return;
        }
        else
        {
            MainPlayer = gameObject.GetComponent<Player>();
            PlayerPhysics = gameObject.GetComponent<Rigidbody2D>();
            PlayerCollider = gameObject.GetComponent<BoxCollider2D>();
            PlayerAnimator = gameObject.GetComponent<Animator>();
            if (MainPlayer != null && PlayerPhysics != null)
            {
                PlayerNumber = (int)XboxInput;
                //No setup anymore!
            }
        }

    }
Example #11
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 1366;
            graphics.PreferredBackBufferHeight = 768;

            Content.RootDirectory = "Content";

            sb = new SpriteBatch(GraphicsDevice);

            input = new InputHandler(this);

            this.Components.Add(input);

            celAnimationManager = new CelAnimationManager(this);
            this.Components.Add(celAnimationManager);

            GameManager = new GameStateManager(this);

            PlayingState = new PlayingState(this);
            PausedState = new PausedState(this);
            TitleState = new TitleIntroState(this);
            StartMenuState = new StartMenuState(this);
            EndState = new EndState(this);

            GameManager.ChangeState(TitleState.Value);
            //GameManager.ChangeState(PlayingState.Value);
        }
Example #12
0
        public void InitializeServer()
        {
            gameStateManager = new GameStateManager();

            //string ip = "147.87.243.27";
            serverConfig = new NetPeerConfiguration("pacman");
            //serverConfig.LocalAddress = IPAddress.Parse(ip);
            serverConfig.Port = 666;

            try
            {
                server = new NetServer(serverConfig);
                server.Start();
                networkManager = new ServerNetworkManager(server);
                WriteToLog("Server wurde gestartet...");
            }
            catch (Exception)
            {
                WriteToLog("Fehler! Server nicht gestartet...");
            }

            //networkManager = new NetworkManager(server);
            gameTime = new ServerGameTime();

            inputQueue = new SortedSet<Command>(new MovementComparer());
        }
Example #13
0
    /// <summary>
    /// Start the Birb Client.
    /// </summary>
    /// <returns>Nothing right now.</returns>
    IEnumerator Start()
    {
        gameStateManager = GetComponent<GameStateManager>();
        Uri server = new Uri("ws://birb.herokuapp.com");
        Uri localhost = new Uri("ws://localhost:5000");
        socket = new WebSocket(server);
        callbacks = new Dictionary<BirbMessageCode, Callback>();
        yield return StartCoroutine(socket.Connect());
        int i = 0;

        // Testing
        //RunUnitTests();

        while (true)
        {
            string reply = socket.RecvString();
            if (reply != null)
            {
                Debug.Log("Received: " + reply);
                Process(reply);
            }
            if (socket.Error != null)
            {
                Debug.LogError("Error: " + socket.Error);
                break;
            }
            yield return 0;
        }
        socket.Close();
    }
    public void Start()
    {
        //Grab mainObject prefab to access managers effectively
        mainObject = GameObject.FindGameObjectsWithTag("MainObject")[0];
        if (GameObject.FindGameObjectsWithTag("MainObject").Length > 1)
        {
            GameObject[] mainObjectList = GameObject.FindGameObjectsWithTag("MainObject");
            for (int i = 0; i < mainObjectList.Length; ++i)
            {
                if (mainObjectList[i].GetComponent<GameStateManager>().objectSaved)
                    mainObject = mainObjectList[i];
            }
        }

        // Notice, these are attached to the MainObject
        gameStateManagerRef = mainObject.GetComponent<GameStateManager>();
        animationManagerRef = gameStateManagerRef.GetAnimationManager();
        inputManagerRef = gameStateManagerRef.GetInputManager();
        worldCollisionRef = gameStateManagerRef.GetWorldCollision();

        // This script is attached to the player, so we use 'gameObject' here
        controllerRef = gameObject.GetComponent<TWCharacterController>();

        paperObject = GameObject.FindGameObjectWithTag("background");
    }
Example #15
0
 public SnakeGame()
 {
     Graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     _gameContentManager = new GameContentManager(Content);
     _gameStateManager = new GameStateManager(this, _gameContentManager);
 }
    void Awake()
    {
        LevelIndex = Application.loadedLevel;
        instance = this;
        if (controlsManager == null) {
            GameObject newCM = new GameObject("Control_Manager");
            controlsManager = newCM.AddComponent<ControlsManager>();
            newCM.transform.SetParent(this.transform);
        }
        // GET THE SCORE MANAGER //
        if (scoreManager == null) {
            GameObject newScM = new GameObject("Score_Manager");
            scoreManager = newScM.AddComponent<ScoreManager>();
            newScM.transform.SetParent(this.transform);
        }

        // LETS SETUP A SCENE //
        if (sceneManager == null) {
            GameObject newSM = new GameObject("Scene_Manager");
            sceneManager = newSM.AddComponent<SceneManager>();
            newSM.transform.SetParent(this.transform);
        }
        // link the debugger //
        GameObject dbg = GameObject.Find ("Debugger");
        debugger = dbg.GetComponent<Debugger> ();
    }
Example #17
0
 public GameLoaderState(DwarfGame game, GameStateManager stateManager)
     : base(game, "GameLoaderState", stateManager)
 {
     IsInitialized = false;
     Games = new List<GameLoadDescriptor>();
     ExitThreads = false;
     Threads = new List<Thread>();
 }
 public static GameStateManager Instance()
 {
     instance = GameStateManager.FindObjectOfType (typeof(GameStateManager)) as GameStateManager;
     if (instance == null) {
         print("No GSM in the scene, we have to make one...");
     }
     return instance;
 }
Example #19
0
        public GameState(Game game, GameStateManager manager)
            : base(game)
        {
            _stateManager = manager;

            _childComponents = new List<GameComponent>();
            _tag = this;
        }
Example #20
0
 public WorldGeneratorState(DwarfGame game, GameStateManager stateManager)
     : base(game, "WorldGeneratorState", stateManager)
 {
     GenerationComplete = false;
     ImageMutex = new Mutex();
     Input = new InputManager();
     Settings = new WorldSettings();
 }
Example #21
0
 public EconomyState(DwarfGame game, GameStateManager stateManager, PlayState play)
     : base(game, "EconomyState", stateManager)
 {
     EdgePadding = 32;
     Input = new InputManager();
     PlayState = play;
     EnableScreensaver = false;
     InputManager.KeyReleasedCallback += InputManager_KeyReleasedCallback;
 }
Example #22
0
    public Deck(GameStateManager.Owner owner, Hand hand, GameObject cardPrefab)
    {
        this.owner = owner;
        this.hand = hand;
        this.cardPrefab = cardPrefab;

        InstantiateDeck();
        Shuffle(25);
    }
Example #23
0
    /// <summary>
    /// Unity START
    /// </summary>
    /// <remarks>
    /// <para>
    /// Sets up GDS initialization, gets reference to UIController and it's UIManager component,
    /// SceneController and it's GameStateManager component. Also, adds handler for GSM.SaveGameEvent
    /// and a broadcast listener for "SetupNewGame".
    /// </para>
    /// </remarks>
    void Start()
    {
        GameObject sceneController = gameObject;
        GameObject uic = GameObject.Find("UIController");
        gsm = sceneController.GetComponent<GameStateManager>();
        gsm.SaveGameEvent += SaveGameEventHandler;

        uim = uic.GetComponent<UIManager>();
    }
Example #24
0
 public DeathState(GameStateManager gameStateManager)
     : base(gameStateManager)
 {
     addService(gameStateManager.getService<UnitDrawService>());
     addService(gameStateManager.getService<MapDrawService>());
     addService(gameStateManager.getService<StatusDrawService>());
     addService(gameStateManager.getService<KillCamService>());
     addService(gameStateManager.getService<DeathService>());
 }
Example #25
0
 void Start()
 {
     if (instance != null) {
         GameObject.Destroy (gameObject);
     } else {
         GameObject.DontDestroyOnLoad (gameObject);
         instance = this;
     }
 }
Example #26
0
 void Awake()
 {
     if (Instance == null) {
         Instance = this;
         DontDestroyOnLoad (gameObject);
     }
     else if (Instance != null) {
         Destroy(gameObject);
     }
 }
Example #27
0
    public PlayingState(GameStateManager gameManager)
    {
        manager = gameManager;
        manager.CameraPos(GameObject.Find("PlayerCam"));
        Time.timeScale = 1;

        HidePlayButton();

        Debug.Log("Playingstate");
    }
    /// <summary>
    /// Unity START
    /// </summary>
    /// <remarks>
    /// <para>
    /// Gets referneces to the MainMenuController, and the UIController, and the
    /// components GameStateManager and UIManager respectively. Also, adds an
    /// event handler to the GSM.LoadGameEvent.
    /// </para>
    /// </remarks>
    void Start()
    {
        GameObject mmc = GameObject.Find("MainMenuController");
        GameObject uic = GameObject.Find("UIController");
        gsm = mmc.GetComponent<GameStateManager>();
        uim = uic.GetComponent<UIManager>();

        gsm.LoadGameEvent += LoadGameEventHandler;

    }
Example #29
0
 protected GameState(Game game, GameStateManager manager, SpriteBatch spriteBatch, Rectangle screenRectangle)
     : base(game)
 {
     _StateManager = manager;
     _ChildComponents = new List<GameComponent>();
     _Tag = this;
     _GameRef = game;
     this.SpriteBatch = spriteBatch;
     this.ScreenRectangle = screenRectangle;
 }
Example #30
0
        public ScreenManager(Game game)
            : base(game)
        {
            this.gamePads = new List<GamepadController>();
            this.fonts = new Dictionary<string, SpriteFont>();

            this.gameStateManager = new GameStateManager();
            this.gameStateManager.CurrentState = GameState.StartScreen;
            this.soundController = new SoundController(this);
        }
 public SinglePlayerGameModeMenuScreen(Game game, GameStateManager manager)
     : base(game, manager)
 {
     MenuString = new string[] { "Adventure", "Challenge", "Match", "Back" };
 }
Example #32
0
 public LobbyMenuScreen(Game game, GameStateManager manager)
     : base(game, manager)
 {
 }
Example #33
0
 private void Start()
 {
     gm = GameObject.Find("Game Manager").GetComponent <GameStateManager>();
 }
Example #34
0
 // Use this for initialization
 void Start()
 {
     gameStateManager = GameObject.Find("GameStateManager").GetComponent <GameStateManager>();//获取当前的游戏状态。
 }
Example #35
0
 public ItemMenuScreen(Game game, GameStateManager manager)
     : base(game, manager)
 {
 }
 public GameStateBase(GameStateManager p_gameStateManager)
 {
     m_gameStateManager = p_gameStateManager;
 }
 private void Awake()
 {
     mGameStateManager = FindObjectOfType <GameStateManager>();
 }
Example #38
0
 public Manual(Game game, GameStateManager manager)
     : base(game, manager)
 {
     base.Initialize();
 }
 // Sets the instance to null when the application quits
 public void OnApplicationQuit()
 {
     instance = null;
 }
        //constructor
        public MultiPlayerMenu(ref GraphicsDeviceManager graphics, Game game, ref SpriteBatch spriteBatch, ref SpriteFont spriteFont, ref String[] menuItems, ref InputHandler newInput, ref Texture2D newBackground, ref GameStateManager currentState, String newMenuTitle, ref Race newRace, ref Player newcurrentplayer, ref GameTime activated, ref OptionsManager optionsManager)
            : base(ref graphics, game, ref spriteBatch, ref spriteFont, ref menuItems, ref newInput, ref newBackground, ref currentState, ref activated)
        {
            optionsM = optionsManager;

            mapIndex  = 0;
            carIndex1 = 0;
            carIndex2 = 0;

            car1 = cars[carIndex1];
            car2 = cars[carIndex2];

            player1Name = "unnamedPlayer1";
            player2Name = "unnamedPlayer2";

            map = maps[mapIndex];

            gearBox1   = optionsM.GearBox1;
            gearIndex1 = optionsM.GearIndex1;

            gearBox2   = optionsM.GearBox2;
            gearIndex2 = optionsM.GearIndex2;

            currentplayer = newcurrentplayer;
            background    = newBackground;
            currentRace   = newRace;
            menuTitle     = newMenuTitle;
        }
Example #41
0
 void updateScreen()
 {
     GUI.Box(new Rect(10, 10, 200, 30), "score: " + GameStateManager.getScore());
     GUI.Box(new Rect(10, 40, 200, 30), "lives: " + GameStateManager.getLives());
     GUI.Box(new Rect(10, 70, 200, 30), "time: " + displayTime);
 }
 public static void Update(float dt)
 {
     Console.ReadKey(true);
     GameStateManager.SetNextState(GameStateTable.GAMESTATE_ENUM.GsQuit);
 }
Example #43
0
 void Awake()
 {
     instance = this;
     loadGameState();
 }
 public HighscoreScreen(Game game, GameStateManager stateManager)
     : base(game, stateManager)
 {
     linkLabelHandler = new EventHandler(addSelectedResource);
 }
Example #45
0
 public SwitchRightCommand(GameStateManager gameStateManager)
 {
     this.gameStateManager = gameStateManager;
 }
Example #46
0
 public XnaGame()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     gameStateManager      = new GameStateManager(this);
 }
Example #47
0
    public bool evaluate()
    {
        string rightSideValue = "";
        string leftSideValue  = "";
        int    leftSideInt    = 0;
        int    rightSideInt   = 0;

        switch (ownComparison)
        {
        case comparisonTypes._true:
            return(true);

        case comparisonTypes._false:
            return(false);
        }

        GameStateManager state = GameStateManager.getGameStateManager();

        switch (rightSideComparable)
        {
        case comparableTypes.constant:
            rightSideValue = rightSide;
            break;

        case comparableTypes.variable:
            rightSideValue = state.getGameVar(rightSide);
            break;

        case comparableTypes.item:
            rightSideValue = state.getItem(rightItemType).ToString();
            break;
        }

        switch (leftSideComparable)
        {
        case comparableTypes.constant:
            leftSideValue = leftSide;
            break;

        case comparableTypes.variable:
            leftSideValue = state.getGameVar(leftSide);
            break;

        case comparableTypes.item:
            leftSideValue = state.getItem(leftItemType).ToString();
            break;

        // [CHANGE] Allow money to be selected as a left-side comparable type
        case comparableTypes.money:
            leftSideInt = state.money;
            break;
        }

        if (ownComparison == comparisonTypes.eq)
        {
            return(leftSideValue == rightSideValue);
        }


        try{
            rightSideInt = int.Parse(rightSideValue);
        }catch (FormatException) {
            Debug.LogError("the right side value: \"" + rightSideValue + "\" is being used in an integer comparison but cannot be converted to an int");
            return(false);
        }
        // [EXTENSION] if not money (which is already an int), then convert leftSideValue to an int
        if (leftSideComparable != comparableTypes.money)
        {
            try {
                leftSideInt = int.Parse(leftSideValue);
            } catch (FormatException) {
                Debug.LogError("the left side value: \"" + leftSideValue + "\" is being used in an integer comparison but cannot be converted to an int");
                return(false);
            }
        }

        switch (ownComparison)
        {
        case comparisonTypes.lt:
            return(leftSideInt < rightSideInt);

        case comparisonTypes.gt:
            return(leftSideInt > rightSideInt);

        case comparisonTypes.le:
            return(leftSideInt <= rightSideInt);

        case comparisonTypes.ge:
            return(leftSideInt >= rightSideInt);
        }

        throw (new Exception("unknown error"));
    }
    public void EndVictory()
    {
//        SoundManager.inst.PlaySFXOneShot(9);
        clickText.SetActive(true);
        GameStateManager.GetInstance().ChangeState(GameStateManager.GameState.VictoryWaintInput);
    }
Example #49
0
        // Update is called once per frame
        private void Update()
        {
            if (GameStateManager.GetCurrentState() != GameStateManager.Types.Setup)
            {
                ani.SetBool("Attacking", false);
                ani.SetBool("Hit", false);
                if (Healthbar.value > 0)
                {
                    //if (Healthbar.value <= 0)
                    //{
                    //send to game over screen?
                    //    return;
                    //}

                    RotateView();
                    // the jump state needs to read here to make sure it is not missed
                    if (!m_Jump)
                    {
                        m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
                    }

                    if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
                    {
                        StartCoroutine(m_JumpBob.DoBobCycle());
                        PlayLandingSound();
                        m_MoveDir.y = 0f;
                        m_Jumping   = false;
                    }
                    if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
                    {
                        m_MoveDir.y = 0f;
                    }

                    //Remove!
                    if (Input.GetKeyDown(KeyCode.J))
                    {
                        TakeDamage(5);
                    }
                    //Remove!

                    m_PreviouslyGrounded = m_CharacterController.isGrounded;
                }
                else if (lives > 0)
                {
                    lives                  += -1;
                    Healthbar.value         = 100;
                    this.transform.position = respawn.transform.position;
                }
                else
                {
                    ani.SetBool("Dead", true);
                    GameStateManager.SetCurrentState(GameStateManager.Types.ViveWin);
                    if (ani.GetCurrentAnimatorStateInfo(0).IsName("Unarmed-Death1"))
                    {
                        ani.StopPlayback();
                    }
                }

                if (weapon.WeaponAnimations.GetBool("isAttacking") && attackSoundPlay)
                {
                    attackSoundPlay     = false;
                    attackSoundCooldown = Time.time;
                    AudioSource.PlayClipAtPoint(attackSound, transform.position, 0.3f);
                    ani.SetBool("Attacking", true);
                }

                if (Time.time >= attackSoundCooldown + 1.0f)
                {
                    attackSoundPlay = true;
                }
            }
        }
Example #50
0
 public override void Open()
 {
     StateMgr = new GameStateManager();
     StateMgr.Push(new MainMenuState());
 }
Example #51
0
 private void Awake()
 {
     instance = this;
 }
 /// <summary>
 /// Closes building detail popup
 /// </summary>
 public void ClosePopup()
 {
     GameStateManager.SetGameState(GameStates.Playing);
     Destroy(gameObject);
 }
 public void StartVictory()
 {
     GameStateManager.GetInstance().ChangeState(GameStateManager.GameState.VictorySequence);
 }
Example #54
0
        public void Chat()
        {
            var           Employee   = this;
            Func <string> get_status = () => Employee.Stats.GetStatusAdjective();

            Employee.World.Paused = true;
            // Prepare conversation memory for an envoy conversation.
            var cMem = Employee.World.ConversationMemory;

            cMem.SetValue("$world", new Yarn.Value(Employee.World));
            cMem.SetValue("$employee", new Yarn.Value(Employee));
            cMem.SetValue("$employee_name", new Yarn.Value(Employee.Stats.FullName));
            cMem.SetValue("$employee_status", new Yarn.Value(get_status()));
            var timeOfDay = "Morning";
            int hour      = Employee.World.Time.CurrentDate.Hour;

            if (hour > 12)
            {
                timeOfDay = "Afternoon";
            }

            if (hour > 16)
            {
                timeOfDay = "Evening";
            }
            cMem.SetValue("$time_of_day", new Yarn.Value(timeOfDay));
            cMem.SetValue("$is_asleep", new Yarn.Value(Employee.Stats.IsAsleep));
            cMem.SetValue("$is_on_strike", new Yarn.Value(Employee.Stats.IsOnStrike));

            if (Employee.Creature.Physics.GetComponent <DwarfThoughts>().HasValue(out var thoughts))
            {
                cMem.SetValue("$grievences", new Yarn.Value(TextGenerator.GetListString(thoughts.Thoughts.Where(thought => thought.HappinessModifier < 0).Select(thought => thought.Description))));
                cMem.SetValue("$good_things", new Yarn.Value(TextGenerator.GetListString(thoughts.Thoughts.Where(thought => thought.HappinessModifier >= 0).Select(thought => thought.Description))));
            }
            else
            {
                cMem.SetValue("$grievences", new Yarn.Value(""));
                cMem.SetValue("$good_things", new Yarn.Value(""));
            }

            String[] personalities = { "happy", "grumpy", "anxious" };
            var      myRandom      = new Random(Employee.Stats.RandomSeed);

            cMem.SetValue("$personality", new Yarn.Value(personalities[myRandom.Next(0, personalities.Length)]));
            cMem.SetValue("$motto", new Yarn.Value(Employee.World.PlayerFaction.Economy.Information.Motto));
            cMem.SetValue("$company_name", new Yarn.Value(Employee.World.PlayerFaction.Economy.Information.Name));
            cMem.SetValue("$employee_task", new Yarn.Value(Employee.CurrentTask.HasValue(out var currentTask) ? "Nothing" : currentTask.Name));
            cMem.SetValue("$employee_class", new Yarn.Value(Employee.Stats.CurrentClass.Name));
            var injuries = TextGenerator.GetListString(Employee.Creature.Stats.Buffs.OfType <Disease>().Select(disease => disease.Name));

            if (injuries == "")
            {
                injuries = "no problems";
            }
            cMem.SetValue("$injuries", new Yarn.Value(injuries));
            cMem.SetValue("$employee_pay", new Yarn.Value((float)(decimal)Employee.Stats.CurrentLevel.Pay));
            cMem.SetValue("$employee_bonus", new Yarn.Value(4 * (float)(decimal)Employee.Stats.CurrentLevel.Pay));
            cMem.SetValue("$company_money", new Yarn.Value((float)(decimal)Employee.Faction.Economy.Funds));

            if (Employee.Physics.GetComponent <Flammable>().HasValue(out var flames))
            {
                cMem.SetValue("$is_on_fire", new Yarn.Value(flames.IsOnFire));
            }
            else
            {
                cMem.SetValue("$is_on_fire", new Yarn.Value(false));
            }

            var state = new YarnState(World, ContentPaths.employee_conversation, "Start", cMem);

            state.AddEmployeePortrait(Employee);
            state.SetVoicePitch(Employee.Stats.VoicePitch);
            GameStateManager.PushState(state);
        }
Example #55
0
 void Start()
 {
     manager = GameObject.Find("Script Manager").GetComponent <GameStateManager>();
 }
 public CharacterGeneratorScreen(Game game, GameStateManager stateManager)
     : base(game, stateManager)
 {
 }
Example #57
0
 public BaseGameState(Game game, GameStateManager manager)
     : base(game, manager)
 {
     GameRef = (Game1)game;
     playerIndexInControl = PlayerIndex.One;
 }
        //Process the network messages sent by the server. We stored them in a queue during OnReceived(). TODO incomplete
        private void ProcessServerMessages()
        {
            //Only process this function if there is data in queue
            if (dataQueue.Count <= 0)
            {
                return;
            }

            if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.CONNECT)
            {
                isConnected     = true;
                showIfConnected = isConnected;

                if (bDebug)
                {
                    Debug.Log("[Notice] Client connection established with " + udp.Client.RemoteEndPoint.ToString() + ".");
                }
                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Client connection established with server.");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");
                dataQueue.Dequeue();
            }
            else if (!isConnected)
            {
                Debug.LogError("[Error] Received message from server, but cannot process it because client is not connected to server.");
                dataQueue.Clear();
                return;
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.CREATE_ACCOUNT)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] New account created.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Account created successfully.");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");

                if (loginCtrlRef)
                {
                    loginCtrlRef.AccountCreated();
                }
                else if (GameObject.Find("Canvas/Login Controller"))
                {
                    loginCtrlRef = GameObject.Find("Canvas/Login Controller").GetComponent <LoginController>();
                    loginCtrlRef.AccountCreated();
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.FAILED_ACCOUNT_CREATION)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Failed to create new account.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Failed to create account; Invalid username or password.");
                }

                if (loginCtrlRef)
                {
                    loginCtrlRef.UserExists();
                }
                else if (GameObject.Find("Canvas/Login Controller"))
                {
                    loginCtrlRef = GameObject.Find("Canvas/Login Controller").GetComponent <LoginController>();
                    loginCtrlRef.UserExists();
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.LOGIN_ACCOUNT)
            {
                isLoggedIn = true;
                GameStateManager.SetState(State.GAMESELECTSCENE);
                if (bDebug)
                {
                    Debug.Log("[Notice] Client has successfully logged in.");
                }

                //TODO: Exit login screen; Load next scene

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Successfully logged in.");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");

                if (loginCtrlRef)
                {
                    loginCtrlRef.ConfirmServerLogin();
                }
                else if (GameObject.Find("Canvas/Login Controller"))
                {
                    loginCtrlRef = GameObject.Find("Canvas/Login Controller").GetComponent <LoginController>();
                    loginCtrlRef.ConfirmServerLogin();
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.FAILED_LOGIN)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Failed to log in.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Login failed; Invalid username or password.");
                }

                if (loginCtrlRef)
                {
                    loginCtrlRef.IncorrectLogin();
                }
                else if (GameObject.Find("Canvas/Login Controller"))
                {
                    loginCtrlRef = GameObject.Find("Canvas/Login Controller").GetComponent <LoginController>();
                    loginCtrlRef.IncorrectLogin();
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.PING)  //Received a ping from the server
            {
                if (bDebug && bVerboseDebug)
                {
                    Debug.Log("[Routine] Received flag from server: PING.");
                }
                ResponsePong(); //Send a response pong message
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.VERSION)  //Receives a version request from server. Note: Not used in this case as the client sends the version with the first CONNECT message
            {
                if (bDebug)
                {
                    Debug.Log("[Routine] Received flag from server: VERSION.");
                }
                ResponseVersion();
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.INVALID_VERSION)  //Receives an invalid version message from server
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Received flag from server: INVALID_VERSION.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Incompatible client version; disconnecting from server...");
                }

                Disconnect();
                dataQueue.Dequeue();
            }
            else if (!isLoggedIn)
            {
                Debug.LogError("[Error] Received message from server, but cannot process it because client is not logged in.");
                dataQueue.Dequeue();
                return;
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.QUEUE_MATCHMAKING)
            {
                isInMMQueue = true;
                if (bDebug)
                {
                    Debug.Log("[Notice] Received flag from server: QUEUE_MATCHMAKING.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] You have joined matchmaking queue.");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.FAILED_MMQUEUE)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Received flag from server: FAILED_MMQUEUE.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] You have failed to join matchmaking queue.");
                }
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.MATCH_START)
            {
                MoveUpdateData playersData = JsonUtility.FromJson <MoveUpdateData>(dataQueue.Peek());
                isInMatch = true;

                //Receive lobby data
                foreach (PlayerMoveData player in playersData.players)
                {
                    //Update player position and orientation data, and health
                    //Adds players to clientDataDict that aren't added yet
                    UpdatePlayer(player.username, player.position.x, player.position.y, player.position.z, player.orientation.yaw, player.orientation.pitch, player.health);
                }

                if (bDebug)
                {
                    Debug.Log("[Notice] Client's game match has started.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] The match is starting...");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");

                if (!selectCtrlRef)
                {
                    if (GameObject.Find("SelectionController"))
                    {
                        selectCtrlRef = GameObject.Find("SelectionController").GetComponent <SelectionController>();
                        selectCtrlRef.MatchmakingComplete();
                    }
                }
                else
                {
                    selectCtrlRef.MatchmakingComplete();
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.LEAVE_MATCHMAKING)
            {
                isInMMQueue = false;
                isInMatch   = false;

                if (bDebug)
                {
                    Debug.Log("[Notice] Client has left matchmaking queue.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] You have left matchmaking queue.");
                }
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.FETCH_ACCOUNT)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Retrieved profile data.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Retrieved profile data.");
                }
                Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");

                if (!profileMgrRef)
                {
                    if (GameObject.Find("ProfileManager"))
                    {
                        profileMgrRef = GameObject.Find("ProfileManager").GetComponent <ProfileMgr>();
                        profileMgrRef.SetProfile(clientUsername, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); //TODO TEMP
                        clientUsername = profileMgrRef._Username;
                    }
                }
                else
                {
                    profileMgrRef.SetProfile(clientUsername, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); //TODO TEMP
                    clientUsername = profileMgrRef._Username;
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.FAILED_FETCH)
            {
                if (bDebug)
                {
                    Debug.Log("[Notice] Failed to retrieve profile data.");
                }

                if (consoleRef)
                {
                    consoleRef.UpdateChat("[Console] Failed to retrieve profile data.");
                }
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.MATCH_UPDATE)
            {
                MoveUpdateData playersData = JsonUtility.FromJson <MoveUpdateData>(dataQueue.Peek());
                if (bDebug && bVerboseDebug)
                {
                    Debug.Log("[Notice] Received Match Update.");
                }

                if (bDebug && bVerboseDebug)
                {
                    Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");
                }

                //Receive lobby data
                foreach (PlayerMoveData player in playersData.players)
                {
                    //Update player position and orientation data, and health
                    //Adds players to clientDataDict that aren't added yet
                    UpdatePlayer(player.username, player.position.x, player.position.y, player.position.z, player.orientation.yaw, player.orientation.pitch, player.health);
                }

                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.MISSSHOT_UPDATE)
            {
                MissShotsData shotData = JsonUtility.FromJson <MissShotsData>(dataQueue.Peek());
                Debug.Log("[Temp Debug] dataQueue.Count: " + dataQueue.Count);
                dataQueue.Dequeue();

                Debug.Log("[Notice] Received Missed Shot Update.");
                if (bDebug && bVerboseDebug)
                {
                    Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");
                }

                //Dont process gunshots from own client
                if (shotData.usernameOrigin == clientUsername)
                {
                    Debug.Log("    [Notice] Will not process own gunshots...");
                    return;
                }

                if (!gameMgrRef)
                {
                    if (GameObject.Find("GameManager"))
                    {
                        gameMgrRef = GameObject.Find("GameManager").GetComponent <GameplayManager>();
                    }
                }

                if (gameMgrRef)
                {
                    if (clientDataDict.ContainsKey(shotData.usernameOrigin))
                    {
                        StartCoroutine(gameMgrRef.ConveyMissShot(clientDataDict[shotData.usernameOrigin].objChaserReference, new Vector3(shotData.hitPosition.x, shotData.hitPosition.y, shotData.hitPosition.z)));
                    }
                    else
                    {
                        Debug.LogError("[Error] shotData.usernameOrigin is not a valid key in clientDataDict; cannot update miss shot.");
                    }
                }
                else
                {
                    Debug.LogError("[Error] GameplayManager reference missing; cannot update miss shot.");
                }
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.HITSCAN_UPDATE)
            {
                HitScanData shotData = JsonUtility.FromJson <HitScanData>(dataQueue.Peek());

                Debug.Log("[Notice] Received Hit Scan Update.");
                if (bDebug && bVerboseDebug)
                {
                    Debug.Log("[TEMP TEST] Active Scene is '" + SceneManager.GetActiveScene().name + "'.");
                }

                //Dont process gunshots from own client
                if (shotData.usernameOrigin == clientUsername)
                {
                    return;
                }

                if (!gameMgrRef)
                {
                    if (GameObject.Find("GameManager"))
                    {
                        gameMgrRef = GameObject.Find("GameManager").GetComponent <GameplayManager>();
                    }
                }

                if (gameMgrRef)
                {
                    if (clientDataDict.ContainsKey(shotData.usernameOrigin) && clientDataDict.ContainsKey(shotData.usernameTarget))
                    {
                        if (shotData.damage == 0)   //TODO BANDAID FIX
                        {
                            shotData.damage = 20;
                        }

                        //subtract from health
                        if (clientDataDict[shotData.usernameTarget].health - shotData.damage <= 0)
                        {
                            clientDataDict[shotData.usernameTarget].health = 0;
                            StartCoroutine(BandaidDeathRoutine());
                            //SendDeathMessage(shotData.usernameOrigin, shotData.usernameTarget);
                        }
                        else if (clientDataDict[shotData.usernameTarget].health - shotData.damage > 100)
                        {
                            clientDataDict[shotData.usernameTarget].health = 100;
                        }
                        else
                        {
                            clientDataDict[shotData.usernameTarget].health = clientDataDict[shotData.usernameTarget].health - shotData.damage;
                        }

                        Debug.Log("[Notice] health: " + clientDataDict[shotData.usernameTarget].health);

                        if (shotData.usernameTarget == clientUsername)
                        {
                            //update health bar
                            if (!hpBarCtrlRef)
                            {
                                hpBarCtrlRef = GameObject.Find("Canvas/Health").GetComponent <HealthController>();
                            }
                            if (hpBarCtrlRef)
                            {
                                hpBarCtrlRef.HitMe();
                            }
                            StartCoroutine(gameMgrRef.ConveyHitShot(clientDataDict[shotData.usernameOrigin].objChaserReference, clientDataDict[shotData.usernameTarget].objReference, new Vector3(shotData.hitPosition.x, shotData.hitPosition.y, shotData.hitPosition.z), shotData.damage));
                        }
                        else
                        {
                            StartCoroutine(gameMgrRef.ConveyHitShot(clientDataDict[shotData.usernameOrigin].objChaserReference, clientDataDict[shotData.usernameTarget].objChaserReference, new Vector3(shotData.hitPosition.x, shotData.hitPosition.y, shotData.hitPosition.z), shotData.damage));
                        }
                        Debug.Log("[Notice] " + shotData.usernameTarget + " received " + shotData.damage + " gunfire damage from " + shotData.usernameOrigin);
                    }
                    else
                    {
                        Debug.LogError("[Error] shotData.usernameOrigin is not a valid key in clientDataDict; cannot update hit shot.");
                    }
                }
                else
                {
                    Debug.LogError("[Error] GameplayManager reference missing; cannot update hit shot.");
                }
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.RESPAWN)
            {
                RespawnMessage spawnData = JsonUtility.FromJson <RespawnMessage>(dataQueue.Peek());

                Debug.Log("[Notice] Received respawn message.");

                Respawn(new Vector3(spawnData.spawn.x, spawnData.spawn.y, spawnData.spawn.z));
                dataQueue.Dequeue();
            }
            else if (JsonUtility.FromJson <FlagNetMsg>(dataQueue.Peek()).flag == Flag.MATCH_END)
            {
                dataQueue.Dequeue();
            }
        }
Example #59
0
 public IntroState(Game game, GameStateManager gamestate)
     : base(game, gamestate)
 {
 }
Example #60
0
 public GamePlayScreen(Game game, GameStateManager manager)
     : base(game, manager)
 {
 }