Exemplo n.º 1
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                Movement       = new MoveUnit(relX, relY);
                Movement.Done += MoveEnd;
                GameTask.Insert(Movement);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            if (Game.Human == Owner)
            {
                GameTask.Enqueue(Show.CaravanChoice(this, city));
            }

            return(true);
        }
Exemplo n.º 2
0
        public override void Run()
        {
            _player.AddAdvance(_advance);

            if (_player.CurrentResearch == _advance)
            {
                _player.CurrentResearch = null;
                _player.Science         = 0; // fire-eggs 20170729 if player acquires advance from city/steal/hut, do NOT roll-over existing lightbulbs
            }

            if (!_human)
            {
                EndTask();
                return;
            }

            if (_player.CurrentResearch == null)
            {
                GameTask.Enqueue(new TechSelect(_player));
            }

            Screens.Civilopedia civilopedia = new Screens.Civilopedia(_advance, discovered: true);
            civilopedia.Closed += CivilopediaClosed;
            Common.AddScreen(civilopedia);
        }
Exemplo n.º 3
0
    void generateTask()
    {
        GameObject go;
        int        i = Random.Range(0, 2);

        if (i == 0)      //随机生成不同的任务
        {
            go = Instantiate(task0, new Vector3(-500, 0, 0),
                             Quaternion.identity, LeftUpUI.transform) as GameObject;
            go.transform.localPosition = new Vector3(newTaskPos + 95, 0, 0);
            newTaskPos += 190;
        }
        else
        {
            go = Instantiate(task1, new Vector3(-500, 0, 0),
                             Quaternion.identity, LeftUpUI.transform) as GameObject;
            go.transform.localPosition = new Vector3(newTaskPos + 110, 0, 0);
            newTaskPos += 220;
        }
        tasks[curTaskNum]            = new GameTask(Time.time, go);
        tasks[curTaskNum].s          = tasks[curTaskNum].task.transform.GetComponentInChildren <Slider>();
        tasks[curTaskNum].s.maxValue = overTime;
        tasks[curTaskNum].s.minValue = 0;
        tasks[curTaskNum].s.value    = overTime;
        tasks[curTaskNum].type       = i;
        ++curTaskNum;
    }
Exemplo n.º 4
0
 public void CmdTaskFinish(CustomPayload payload)
 {
     if (CurrentTask == null)
     {
         return;
     }
     if (IsHunter && !CurrentTask.HunterActive || !IsHunter && !CurrentTask.VictimActive)
     {
         return;
     }
     if (!CurrentTask.OnTaskFinish(this, payload.Data))
     {
         return;
     }
     if (IsHunter)
     {
         CurrentTask.LastHunterOpened = (float)NetworkTime.time;
     }
     else
     {
         CurrentTask.LastVictimOpened = (float)NetworkTime.time;
     }
     TargetSetTaskFinishedClient(connectionToClient, CurrentTask.gameObject);
     CurrentTask = null;
     TargetSetTask(connectionToClient, null);
 }
Exemplo n.º 5
0
        private void GameYear_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            int gameYear;

            if (!int.TryParse(Value, out gameYear) || gameYear < -4000 || gameYear > 6000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Game Year --", $"The value {Value} is invalid or out of range.", "Please enter a value between -4000 and", "6000."));
            }
            else
            {
                Game.GameTurn = Common.YearToTurn(gameYear);
                GameTask.Enqueue(Message.General($"Game year set to {Game.GameYear}."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Exemplo n.º 6
0
        public ActionResult <string> CreateDefault([FromBody] DefaultParams p)
        {
            string   playerName = _signInManager.UserManager.GetUserName(this.User);
            GameTask game       = GameManager.Instance.CreateDefaultGame(playerName);

            return(Ok(game.Id));
        }
Exemplo n.º 7
0
    private void OnActiveChange()
    {
        if (Active)
        {
            OnActivate();
        }
        else
        {
            OnDeactivate();
        }

        if (isServer)
        {
            int i = 0;
            if (Active && ActivateTask.Length > 0)
            {
                foreach (GameObject taskObject in ActivateTask)
                {
                    GameTask task = taskObject.GetComponent <GameTask>();
                    task.ActivatorObject = this;
                    // task.VictimActive = ActivateForVictim;
                    // task.HunterActive = ActivateForHunter;
                    if (!Off)
                    {
                        task.VictimActive = false;
                        task.HunterActive = false;
                        if (ActivateForVictim)
                        {
                            StartCoroutine(doCooldown(ActivateForVictimCooldown, task, 0));
                        }
                        if (ActivateForHunter)
                        {
                            StartCoroutine(doCooldown(ActivateForHunterCooldown, task, 1));
                        }
                    }
                }
            }
            else if (!Active && DeactivateTask.Length > 0)
            {
                foreach (GameObject taskObject in DeactivateTask)
                {
                    GameTask task = taskObject.GetComponent <GameTask>();
                    task.ActivatorObject = this;
                    if (!Off)
                    {
                        task.VictimActive = false;
                        task.HunterActive = false;
                        if (DeActivateForVictim)
                        {
                            StartCoroutine(doCooldown(DeActivateForVictimCooldown, task, 0));
                        }
                        if (DeActivateForHunter)
                        {
                            StartCoroutine(doCooldown(DeActivateForHunterCooldown, task, 1));
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 8
0
        public GamePlay()
        {
            Cursor = MouseCursor.Pointer;

            Color[] palette = Resources.Instance.LoadPIC("SP257").Palette;

            _canvas = new Picture(320, 200, palette);
            _canvas.FillRectangle(5, 0, 0, 320, 200);

            _rightSideBar = Settings.RightSideBar;

            _menuBar = new MenuBar(palette);
            _sideBar = new SideBar(palette);
            _gameMap = new GameMap();

            _menuBar.GameSelected        += MenuBarGame;
            _menuBar.OrdersSelected      += MenuBarOrders;
            _menuBar.AdvisorsSelected    += MenuBarAdvisors;
            _menuBar.WorldSelected       += MenuBarWorld;
            _menuBar.CivilopediaSelected += MenuBarCivilopedia;

            while (Game.CurrentPlayer != Game.HumanPlayer)
            {
                Game.Instance.Update();
                GameTask.Update();
            }
        }
Exemplo n.º 9
0
        private void PlayerGold_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            short playerGold;

            if (!short.TryParse(Value, out playerGold) || playerGold < 0 || playerGold > 30000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Player Gold --", $"The value {Value} is invalid or out of range.", "Please enter a value between 0 and", "30000."));
            }
            else
            {
                _selectedPlayer.Gold = playerGold;
                GameTask.Enqueue(Message.General($"{_selectedPlayer.TribeName} gold set to {playerGold}$."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Exemplo n.º 10
0
        private async Task StartCountdown()
        {
            while (Info.Owner != null)
            {
                try
                {
                    LastCountdown = 0f;

                    await GameTask.DelaySeconds(Countdown);

                    if (Info.Owner != null)
                    {
                        OnCountdown();
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Trim() == "A task was canceled.")
                    {
                        return;
                    }

                    Log.Error($"[TASK] {e.Message}: {e.StackTrace}");
                }
            }
        }
Exemplo n.º 11
0
        private void Incite(object sender, EventArgs args)
        {
            Player previousOwner = Game.GetPlayer(_cityToIncite.Owner);

            Show captureCity = Show.CaptureCity(_cityToIncite);

            captureCity.Done += (s1, a1) =>
            {
                Game.DisbandUnit(_diplomat);
                _cityToIncite.Owner = _diplomat.Owner;

                // remove half the buildings at random
                foreach (IBuilding building in _cityToIncite.Buildings.Where(b => Common.Random.Next(0, 1) == 1).ToList())
                {
                    _cityToIncite.RemoveBuilding(building);
                }

                _diplomat.Player.Gold -= (short)_inciteCost;

                previousOwner.IsDestroyed();

                if (Human == _cityToIncite.Owner || Human == _diplomat.Owner)
                {
                    GameTask.Insert(Tasks.Show.CityManager(_cityToIncite));
                }
            };

            if (Human == _cityToIncite.Owner || Human == _diplomat.Owner)
            {
                GameTask.Insert(captureCity);
            }

            Cancel();
        }
Exemplo n.º 12
0
        public ChangeActivityOutput <GameTaskDto, long> ChangeActivity(ChangeActivityInput input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTask gameTaskEntity = GameTaskRepository.Get(input.EntityId);

            if (gameTaskEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanChangeActivityForEntity(gameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionChangeActivityDenied, "\"GameTask\"");
            }

            gameTaskEntity.IsActive = input.IsActive == null ? !gameTaskEntity.IsActive : (bool)input.IsActive;

            GameTaskDto newGameTaskDto = (gameTaskEntity).MapTo <GameTaskDto>();

            GameTaskRepository.Update(gameTaskEntity);

            GameTaskRepository.Includes.Clear();

            return(new ChangeActivityOutput <GameTaskDto, long>()
            {
                Entity = newGameTaskDto
            });
        }
Exemplo n.º 13
0
        public UpdateOutput <GameTaskDto, long> Update(UpdateInput <GameTaskDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTask newGameTaskEntity = input.Entity.MapTo <GameTask>();

            if (newGameTaskEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTask\"");
            }

            if (!GameTaskPolicy.CanUpdateEntity(newGameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"GameTask\"");
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTaskRepository.Update(newGameTaskEntity);
            GameTaskDto newGameTaskDto = (GameTaskRepository.Get(newGameTaskEntity.Id)).MapTo <GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new UpdateOutput <GameTaskDto, long>()
            {
                UpdatedEntity = newGameTaskDto
            });
        }
Exemplo n.º 14
0
        public CreateOutput <GameTaskDto, long> Create(CreateInput <GameTaskDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            GameTask newGameTaskEntity = input.Entity.MapTo <GameTask>();

            newGameTaskEntity.IsActive = true;

            if (!GameTaskPolicy.CanCreateEntity(newGameTaskEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"GameTask\"");
            }

            GameTaskRepository.Includes.Add(r => r.LastModifierUser);
            GameTaskRepository.Includes.Add(r => r.CreatorUser);
            GameTaskRepository.Includes.Add(r => r.GameTaskType);
            GameTaskRepository.Includes.Add(r => r.Conditions);
            GameTaskRepository.Includes.Add(r => r.Tips);

            GameTaskDto newGameTaskDto = (GameTaskRepository.Insert(newGameTaskEntity)).MapTo <GameTaskDto>();

            GameTaskRepository.Includes.Clear();

            return(new CreateOutput <GameTaskDto, long>()
            {
                CreatedEntity = newGameTaskDto
            });
        }
Exemplo n.º 15
0
        internal override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            // fire-eggs Caravan can build wonder even in home city
            if (city != null && city.Owner == Owner && Game.Human == Owner)
            {
                // TODO fire-eggs this seems like bad design: how to determine whether to show a menu, without activating the menu?
                if (city.IsBuildingWonder || CaravanChoice.AllowEstablishTradeRoute(this, city))
                {
                    GameTask.Enqueue(Show.CaravanChoice(this, city));
                }
                else
                {
                    MovementTo(relX, relY);
                }
                return(true);
            }

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                MovementTo(relX, relY);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            return(true);
        }
Exemplo n.º 16
0
        private void HandleFuel()
        {
            if (Map[X, Y].Units.Any(u => u.Name == "Carrier"))
            {
                if (CarrierIsLandable())
                {
                    MovesLeft = 0;
                    FuelLeft  = TotalFuel;                              // Refuel
                    return;
                }
            }

            if (Map[X, Y].City != null)
            {
                MovesLeft = 0;
                FuelLeft  = TotalFuel;                                  // Refuel
                return;
            }


            if (MovesLeft > 0 || FuelLeft > 0)
            {
                return;
            }

            // Air unit is out of fuel
            Game.DisbandUnit(this);
            GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/FUEL")));
        }
Exemplo n.º 17
0
        public override bool MouseDown(ScreenEventArgs args)
        {
            if (args.Y <= 50)
            {
                if (args.X < 1 || args.Y < 1 || args.X > 79 || args.Y > 49)
                {
                    return(true);
                }

                int xx = (args.X - 1) + GamePlay.X - 30;
                int yy = (args.Y - 1) + GamePlay.Y - 18;

                GamePlay.CenterOnPoint(xx, yy);
            }
            if (args.Y > 50 && args.Y < 62)
            {
                Log("Sidebar: Palace View");
                Common.AddScreen(new PalaceView());
            }
            else if (args.Y >= 62)
            {
                if (Game.CurrentPlayer == Human && Game.ActiveUnit == null)
                {
                    GameTask.Enqueue(Turn.End());
                }
            }
            return(true);
        }
Exemplo n.º 18
0
        private void PlayerScience_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            short playerScience;

            if (!short.TryParse(Value, out playerScience) || playerScience < 0 || playerScience > 30000)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set Player Science --", $"The value {Value} is invalid or out of range.", "Please enter a value between 0 and", "30000."));
            }
            else
            {
                if (playerScience > _selectedPlayer.ScienceCost)
                {
                    playerScience = _selectedPlayer.ScienceCost;
                }
                _selectedPlayer.Science = playerScience;
                GameTask.Enqueue(Message.General($"{_selectedPlayer.TribeName} science set to {playerScience}~."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Exemplo n.º 19
0
        private void StealTechnology(object sender, EventArgs args)
        {
            IAdvance advance = _diplomat.GetAdvanceToSteal(_enemyCity.Player);

            if (advance == null)
            {
                GameTask.Insert(Message.General($"No new technology found"));
            }
            else
            {
                GameTask task = new Tasks.GetAdvance(_diplomat.Player, advance);

                task.Done += (s1, a1) =>
                {
                    Game.DisbandUnit(_diplomat);
                    if (_diplomat.Player == Human || _enemyCity.Player == Human)
                    {
                        GameTask.Insert(Message.Spy("Spies report:", $"{_diplomat.Player.TribeName} steal", $"{advance.Name}"));
                    }
                };

                GameTask.Enqueue(task);
            }

            Cancel();
        }
Exemplo n.º 20
0
        private void CitySizeSet_Accept(object sender, EventArgs args)
        {
            Value = (sender as Input).Text;

            byte citySize;

            if (!byte.TryParse(Value, out citySize) || citySize < 1 || citySize > 99)
            {
                GameTask.Enqueue(Message.Error("-- DEBUG: Set City Size --", $"The value {Value} is invalid or out of range.", "Please enter a value between 1 and 99."));
            }
            else
            {
                _selectedCity.Size = citySize;
                GameTask.Enqueue(Message.General($"{_selectedCity.Name} size set to {citySize}."));
            }

            if (Accept != null)
            {
                Accept(this, null);
            }
            if (sender is Input)
            {
                ((Input)sender)?.Close();
            }
            Destroy();
        }
Exemplo n.º 21
0
 private void onBattleTaskGoing(GameTask gt)
 {
     if (this.IsHostTask(gt))
     {
         this.TrackTask(gt);
     }
 }
Exemplo n.º 22
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (Game.CurrentPlayer != Human)
            {
                // Ignore all keypresses if the current player is not human
                return(false);
            }

            switch (args.KeyChar)
            {
            case 'G':
                GameTask.Enqueue(Show.Goto);
                return(true);

            case 'T':
                GameTask.Enqueue(Show.Terrain);
                return(true);
            }

            if (Game.ActiveUnit != null)
            {
                return(KeyDownActiveUnit(args));
            }

            switch (args.Key)
            {
            case Key.Space:
            case Key.Enter:
                GameTask.Enqueue(Turn.End());
                return(true);
            }
            return(false);
        }
Exemplo n.º 23
0
        public GameTask GetGamePlayTask(GameLocalDataResponse manifest)
        {
            var platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN");
            var playTask = new GameTask()
            {
                IsBuiltIn = true,
                IsPrimary = true
            };

            if (string.IsNullOrEmpty(platform.fulfillmentAttributes.executePathOverride))
            {
                return(null);
            }

            if (platform.fulfillmentAttributes.executePathOverride.Contains(@"://"))
            {
                playTask.Type = GameTaskType.URL;
                playTask.Path = platform.fulfillmentAttributes.executePathOverride;
            }
            else
            {
                var executePath = GetPathFromPlatformPath(platform.fulfillmentAttributes.executePathOverride);
                playTask.WorkingDir = Path.GetDirectoryName(GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride));
                playTask.Path       = executePath;
            }

            return(playTask);
        }
Exemplo n.º 24
0
 protected void MovementTo(int relX, int relY)
 {
     MovementStart(Tile);
     Movement       = new MoveUnit(relX, relY);
     Movement.Done += MoveEnd;
     GameTask.Insert(Movement);
 }
Exemplo n.º 25
0
        public static void ActivateTask(GameTask task, Game gameData, EmulatorProfile config)
        {
            switch (task.Type)
            {
            case GameTaskType.File:
            case GameTaskType.URL:
                ActivateTask(task, gameData);
                break;

            case GameTaskType.Emulator:
                if (config == null)
                {
                    throw new Exception("Cannot start emulated game without emulator.");
                }

                var path      = gameData.ResolveVariables(config.Executable);
                var arguments = gameData.ResolveVariables(config.Arguments);
                if (!string.IsNullOrEmpty(task.AdditionalArguments))
                {
                    arguments += " " + gameData.ResolveVariables(task.AdditionalArguments);
                }

                if (task.OverrideDefaultArgs)
                {
                    arguments = gameData.ResolveVariables(task.Arguments);
                }

                var workdir = gameData.ResolveVariables(config.WorkingDirectory);
                logger.Info($"Starting emulator: {path}, {arguments}, {workdir}");
                ProcessStarter.StartProcess(path, arguments, workdir);
                break;
            }
        }
Exemplo n.º 26
0
        public async Task <IActionResult> GameRestart(int roomId)
        {
            if (gameServer.gameHelper.gameTasks.FirstOrDefault(game => game.Game.Room.Id == roomId)?.IsStarted == true)
            {
                return(Ok("Gra dla tego pokoju już działa."));
            }

            var room = await roomService.GetRoom(roomId);

            if (room.Players.Count < 2)
            {
                return(Ok("Oczekiwanie na graczy."));
            }

            var playerEmptyPoints = room.Players.ToDictionary(player => player.Id, _ => 0);

            var gameTask = new GameTask
                           (
                new ChessGameStatus
            {
                WhiteClock = room.RoomConfiguration.RoundDuration,
                BlackClock = room.RoomConfiguration.RoundDuration
            },
                new Game
            {
                Id   = Guid.NewGuid().ToString(),
                Room = room,
                PlayersPointsPerGame = playerEmptyPoints
            }
                           );

            await gameServer.CreateGame(gameTask);

            return(Ok());
        }
Exemplo n.º 27
0
        public override void Play(List <Emulator> emulators)
        {
            ReleaseResources();
            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += Monitor_TreeDestroyed;
            var app = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

            if (Game.PlayTask.Type == GameTaskType.URL && Game.PlayTask.Path.StartsWith("battlenet", StringComparison.InvariantCultureIgnoreCase))
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var task = new GameTask()
                {
                    Path      = BattleNetSettings.ClientExecPath,
                    Arguments = string.Format("--exec=\"launch {0}\"", Game.ProviderId)
                };

                GameHandler.ActivateTask(task, Game, emulators);
                procMon.TreeStarted += ProcMon_TreeStarted;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else if (app.Type == BattleNetLibrary.BNetAppType.Classic && Game.PlayTask.Path.Contains(app.ClassicExecutable))
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var proc = GameHandler.ActivateTask(Game.PlayTask, Game, emulators);
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, true);
                OnStarted(this, new GameControllerEventArgs(this, 0));
            }
            else
            {
                base.Play(emulators);
            }
        }
Exemplo n.º 28
0
 private void onBattleTaskClose(GameTask gt)
 {
     if (!this.IsHostTask(gt))
     {
         return;
     }
 }
Exemplo n.º 29
0
 private MenuItem <int> MenuBuildIrrigation() => MenuItem <int>
 .Create((Map[X, Y] is Forest)? "Change to Plains" :
         ((Map[X, Y] is Jungle) || (Map[X, Y] is Swamp))? "Change to Grassland" :
         "Build Irrigation")
 .SetShortcut("i")
 .SetEnabled(Map[X, Y].AllowIrrigation() || Map[X, Y].AllowChangeTerrain())
 .OnSelect((s, a) => GameTask.Enqueue(Orders.BuildIrrigation(this)));
Exemplo n.º 30
0
    void Update()
    {
        if (!SceneTransitionManager.instance.isGameOn())
        {
            return;
        }
        // Debug.Log("hi~~~~~");
        if (!TaskManager.instance.filledUI)
        {
            return;                                 // used once since GAME scene is never destroyed
        }
        // Debug.Log("heyyy");
        // Debug.Log(addTextDoneCountdown);

        var completedTaskIdx = -1;

        // For each active task
        for (int i = 0; i < activeTasks.Count; i++)
        {
            // If the task has been completed
            if (TaskManager.instance.activeTasks[i].isComplete())
            {
                Debug.Log("Task " + TaskManager.instance.activeTasks[i].description + " has been completed");
                completedTaskIdx = i;
                break;
            }

            pauseMenuTasks[i].text = TaskManager.instance.activeTasks[i].description;
            onScreenTasks[i].text  = TaskManager.instance.activeTasks[i].description;
        }
        // Completed a task
        if (completedTaskIdx != -1)
        {
            // Remove the completed task and add a new one
            SFX.PlayOneShot(ObjCompleteSFX, 0.6F);
            var completedTask = activeTasks[completedTaskIdx];
            activeTasks[completedTaskIdx] = null;
            completedTasks.Add(completedTask);
            GameTask newTask = null;
            newTask = addRandomTask();
            Debug.Log(newTask);
            pauseMenuTasks[completedTaskIdx].text = newTask.description;
            onScreenTasks[completedTaskIdx].text  = newTask.description;

            // Show objective complete
            // Debug.Log("Calling showobjectivecomplete");
            TaskManager.instance.StopCoroutine("ShowObjectiveComplete");
            TaskManager.instance.StopCoroutine("ShowNewObjective");
            TaskManager.instance.StartCoroutine(ShowObjectiveComplete(completedTask));
            TaskManager.instance.StartCoroutine(ShowNewObjective(newTask));

            // Generate a tool for the raccoon here
            // Debug.Log("Calling spawnrandomtool");

            SpawnRandomTool();
        }

        // update task text if there are changes
    }
Exemplo n.º 31
0
        public void SaveCharTask(GameTask task)
        {
            //var charTasksNode = (XmlElement)CharNode(task.CharIdx).SelectSingleNode("Tasks");
            var charTasksNode = CharTasksNode(task.CharIdx);
            var taskNodeName = task.XmlNodeName;

            var taskNode = (XmlElement)charTasksNode.SelectSingleNode(taskNodeName);

            if (taskNode == null) {
                task.AppendXmlElement(charTasksNode);
            } else {
                task.SetXmlAttribs(taskNode);
            }

            SaveFile();
        }
Exemplo n.º 32
0
        public GameTask Add(GameTask gameTask)
        {
            bool taskMatureTimeUnique = false;
            uint attempts = 0;

            while (taskMatureTimeUnique == false) {
                ArgumentException aex = new ArgumentException();

                if (this.Queue.ContainsKey(gameTask.MatureTime.Ticks)) {
                    taskMatureTimeUnique = false;
                } else {
                    taskMatureTimeUnique = true;

                    try {
                        Queue.Add(gameTask.MatureTime.Ticks, gameTask);
                    } catch (ArgumentException aexNew) {
                        MessageBox.Show("Failed to add task with key: '" + gameTask.MatureTime.Ticks + "'.");
                        aex = aexNew;
                    }
                }

                if (taskMatureTimeUnique == false) {
                    gameTask = gameTask.AddTicks(1);
                }

                attempts += 1;

                if (attempts > 500) {
                    MessageBox.Show("GameTaskQueue::Add(): Error adding task: " + aex.ToString());
                }
            }

            return gameTask;
        }
Exemplo n.º 33
0
        public bool TryGetCharTask(uint charIdx, TaskKind kind, int taskId, out GameTask task)
        {
            //var charTasksNode = (XmlElement)CharNode(charIdx).SelectSingleNode("Tasks");
            var charTasksNode = CharTasksNode(charIdx);
            var taskNodeName = GameTask.GenXmlNodeName(kind, taskId);
            var taskNode = (XmlElement)charTasksNode.SelectSingleNode(taskNodeName);

            if (taskNode != null) {
                try {
                    task = GameTask.FromXmlElement(taskNode);
                    return true;
                } catch (Exception) { }
            }

            task = new GameTask();
            return false;
        }
Exemplo n.º 34
0
        // Populates queue taking in to account last invoke times.
        public void Populate(Interactor intr, int charsMax, bool resetDay)
        {
            var now = DateTime.Now;

            for (uint charIdx = 0; charIdx < charsMax; charIdx++) {

                // ################################### INVOCATION #####################################
                int invokesToday = intr.AccountStates.GetCharStateOr(charIdx, "invokesToday", 0);

                DateTime invokesCompletedOn = intr.AccountStates.GetCharStateOr(charIdx,
                    "invokesCompleteFor", Global.Default.SomeOldDate);

                // Clear any stale invoke count:
                if (invokesCompletedOn < TodaysGameDate.AddDays(-1)) {
                    invokesToday = 0;
                }

                DateTime mostRecentInvoke = intr.AccountStates.GetCharStateOr(charIdx, "mostRecentInvocationTime",
                    now.AddHours(-24));

                var invTaskMatureTime = CalculateTaskMatureTime(mostRecentInvoke, charIdx,
                    TaskKind.Invocation, invokesToday, 0.0f);

                if (invokesToday >= 6) {
                    if (invokesCompletedOn < TodaysGameDate) { // START FRESH DAY
                        intr.AccountStates.SaveCharState(0, charIdx, "invokesToday");
                        invokesToday = 0;
                        invTaskMatureTime = now;
                    } else { // DONE FOR THE DAY
                        invTaskMatureTime = NextThreeAmPst;
                    }
                }

                if (resetDay) {
                    intr.AccountStates.SaveCharState(0, charIdx, "invokesToday");
                    intr.AccountStates.SaveCharState(TodaysGameDate.AddDays(-1), charIdx,
                        "mostRecentInvocationTime");
                    invokesToday = 0;
                    invTaskMatureTime = now;
                }

                intr.Log(LogEntryType.Debug, "Adding invocation task to queue for character [{0}], matures: {1}.",
                    charIdx, invTaskMatureTime);

                var invTask = new GameTask(mostRecentInvoke, invTaskMatureTime, charIdx, TaskKind.Invocation, invokesToday, 0.0f);
                intr.AccountStates.SaveCharTask(invTask);
                this.Add(invTask);

                // ################################## PROFESSIONS #####################################
                // ################ Prune Stale Profession Tasks ################
                //for (var p = 0; p < ProfessionTasksRef.ProfessionTaskNames.Length; p++) {
                //	var settingKey = "MostRecentProfTime_" + p;
                //	var oldTaskThreshold = now.AddDays(-2);

                //	//DateTime profTaskMatureTime;

                //	//if (DateTime.TryParse(intr.AccountStates.GetCharStateOr(charIdx,
                //	//			charSettingSection, ""), out profTaskMatureTime)) {
                //	//	intr.Log("Found " + settingKey + " for " + charSettingSection + " in ini file: " +
                //	//		profTaskMatureTime.ToString() + ".", LogEntryType.Debug);

                //	//	//// [TODO]: Is this necessary?:
                //	//	//if (profTaskMatureTime < oldTaskThreshold) {
                //	//	//	intr.Log("Removing " + settingKey + " for " + charSettingSection + " from ini file.", LogEntryType.Debug);
                //	//	//	intr.GameAccount.RemoveSetting(settingKey, charSettingSection);
                //	//	//}
                //	//}
                //	DateTime profTaskMatureTime = intr.AccountStates.GetCharStateOr(charIdx,
                //		settingKey, Global.Default.SomeOldDate);
                //}

                // ################ Add Tasks to Queue ################
                int tasksQueued = 0;

                for (var taskId = 0; taskId < ProfessionTasksRef.ProfessionTaskNames.Length; taskId++) {
                    GameTask profTask;

                    // Attempt to load from new task persistence system:
                    if (!intr.AccountStates.TryGetCharTask(charIdx, TaskKind.Profession, taskId, out profTask)) {
                        // Use old school system:
                        var mostRecentTaskTime = intr.AccountStates.GetCharStateOr(charIdx, "MostRecentProfTime_" + taskId, Global.Default.SomeOldDate);
                        DateTime profTaskMatureTime = CalculateTaskMatureTime(mostRecentTaskTime, charIdx, TaskKind.Profession, taskId, 0.0f);
                        profTask = new GameTask(mostRecentTaskTime, profTaskMatureTime, charIdx, TaskKind.Profession, taskId, 0.0f);
                    }

                    intr.Log(LogEntryType.Info, "Adding profession task to queue for character [" + charIdx
                        + "], matures: " + profTask.MatureTime.ToString() + ", taskId: " + taskId.ToString() + ".");
                    this.Add(profTask);
                    tasksQueued += 1;
                }

                intr.Log(LogEntryType.Info, "[" + tasksQueued.ToString() + "] profession tasks queued for character [" + charIdx + "].");
            }
        }