예제 #1
0
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var    game    = (Game)information.Context;
            string message = "";

            switch (game.GameState)
            {
            case Enums.GameState.MainMenu:
                message = "You are in the main menu. Say new game to begin, or say rules to learn how to play. ";
                break;

            case Enums.GameState.PlayerTurn:
                message = "Here's a reference for all commands: 1. End turn. 2. Transform. 3. Assign tactical crew to weapons. 4. Fire weapons. 5. Fire stasis beam. 6. Recharge Shields. 7. Heal Crew. 8. Remove Threat. 9. Repair Hull. 10. Send crew on a mission. 11. Return crew from a mission. 12. I need more  time. 13. Status. 14. Threat status. 15. Threat information. ";
                break;

            case Enums.GameState.FiringWeapons:
                message = "You have assigned tactical crew to your weapons. Say fire weapons to open fire. ";
                break;

            case Enums.GameState.ContinueGamePrompt:
                message = "Say yes to continue playing your last unfinished game. Say no to go to the main menu.";
                break;

            case Enums.GameState.Rules:
                message = "Say next to continue to the next rule, back to go back to the previous rule, or repeat to repeat the current rule. You can say new game at any point to start a new game. ";
                break;
            }


            return(ResponseCreator.Ask(message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before healing your crew. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("You cannot heal the crew in this ship. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Medical && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available medical crew to heal our units in the infirmary. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.InfirmaryCrewCount < 1)
            {
                return(ResponseCreator.Ask("There are no crew members in the infirmary. Use this command when someone ends up in the infirmary. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // we are good to go, heal the units in t he infirmary
            ship.HealCrew();

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (_intentName == BuiltInIntent.Yes)
            {
                // we should continue previous game
                game.Message         = game.RepeatMessage;
                game.RepromptMessage = "Awaiting your orders, captain. ";
                game.GameState       = game.LastGameState;
                game.SaveData();
            }
            else if (_intentName == BuiltInIntent.No)
            {
                // answer was No, go back to main menu
                game.IsGameInProgress = false;
                game.Welcome();
            }
            else
            {
                // invalid answer, ask the continue game prompt again
                return(ResponseCreator.Ask("I'm sorry, I didn't get that. Do you want to continue playing your last unfinished game? ", "To continue your last game, say yes. Otherwise, say no. ", information.SkillRequest.Session));
            }

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("To get information about the current active threats, you need to start a new game. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            if (game.ThreatManager.ExternalThreats.Count < 1 && game.ThreatManager.InternalThreats.Count < 1)
            {
                return(ResponseCreator.Ask("There are no active threats at the moment. Use the threat information command when you need information about an active threat. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            string message  = "";
            var    request  = (IntentRequest)information.SkillRequest.Request;
            string threatId = request.Intent.Slots["Threat"].GetSlotId();
            var    threat   = game.ThreatManager.GetActiveThreat(threatId);

            if (threat == null)
            {
                string threatName = request.Intent.Slots["Threat"].Value;
                return(ResponseCreator.Ask($"{threatName} is not a valid active threat. Try the threat information command again and provide one of the following: {game.ThreatManager.GetThreatsAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // valid active threat let's grab the info message
            message += threat.GetInfoMessage();
            message += "What are your orders, captain? ";

            game.Message = message;

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
예제 #5
0
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before removing locked threats from your scanners. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("You cannot remove the locked threats from  your scanners in this ship. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Medical && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available medical crew to remove a locked threat from our scanners. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ScannerCount < 1)
            {
                return(ResponseCreator.Ask("There are no locked threats on our scannerse. Use this command when you roll a threat that gets locked on the scanners. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // we are good to go, remove a threat from the scanner
            ship.RemoveThreatFromScanner();

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var    game    = (Game)information.Context;
            string message = "I'm sorry Captain, that is not a valid command. ";

            return(ResponseCreator.Ask(message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override async Task <SkillResponse> Handle(AlexaRequestInformation <SkillRequest> information)
        {
            var    game    = (Game)information.Context;
            string message = "I'm sorry Captain, that is not a valid command. Say help if you need assistance. ";

            return(ResponseCreator.Ask(message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before firing the stasis beam. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("Our ship does not have a stasis beam. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Science && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available science crew to fire the stasis beam. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (game.ThreatManager.ExternalThreats.Count < 1 && game.ThreatManager.InternalThreats.Count < 1)
            {
                return(ResponseCreator.Ask("There are no threats to disable with the stasis beam. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ShipSystems["ScienceUnavailable"])
            {
                return(ResponseCreator.Ask("Our science crew are having an existentialism crisis and are unavailable. Send a science crew on a mission to deal with cosmic existentialism to be able to use them again. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if enemy target is present
            var    request  = (IntentRequest)information.SkillRequest.Request;
            string threatId = request.Intent.Slots["Threat"].GetSlotId();
            var    threat   = game.ThreatManager.GetActiveThreat(threatId);

            if (threat == null)
            {
                string threatName = request.Intent.Slots["Threat"].Value;
                return(ResponseCreator.Ask($"{threatName} is not a valid target. Try firing the stasis beam again and provide one of the following: {game.ThreatManager.GetThreatsAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // we have a valid target, let's check if it is already disabled
            if (threat.IsDisabled)
            {
                return(ResponseCreator.Ask($"{threat.Name} is already disabled. We can use the stasis beam on targets that are still active. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // we have a valid target, fire the stasis beam
            ship.FireStasisBeam(threat);

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before ending your turn. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            game.EndTurn();

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game       = (Game)information.Context;
            var request    = (IntentRequest)information.SkillRequest.Request;
            int difficulty = request.Intent.Slots["NoPanicNumber"].ExtractNumber();

            if (difficulty < 0 || difficulty > 6)
            {
                return(ResponseCreator.Ask($"Please provide a valid difficulty level. Say new game again and provide a number between zero and six. A Higher number of Don't Panic cards will make the game easier. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            game.CreateNewGame(difficulty);

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("To learn about the ship's status, you need to start a game. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }


            var    ship    = game.Ship;
            string message = "";

            if (_intentName == "ShipStatusIntent" || _intentName == "CrewStatusIntent")
            {
                message += ship.AvailableCrewCount > 0 ? $"{ship.GetAvailableCrewAsString()} waiting for orders. " : "We have no available crew. ";
                if (ship.MissionCrewCount > 0)
                {
                    var crewOnMissions = ship.Crew.Where(c => c.State == Enums.CrewState.Mission);
                    foreach (var item in crewOnMissions)
                    {
                        message += $"{item.Type.ToString()} is sent on a mission to deal with {item.MissionName}. ";
                    }
                }
                message += ship.InfirmaryCrewCount > 0 ? $"We have {ship.InfirmaryCrewCount} crew in the infirmary. " : "";
            }

            if (_intentName == "ShipStatusIntent")
            {
                message += ship.ScannerCount > 0 ? $"The number of locked threats on our scanners is {ship.ScannerCount}. " : "";
            }

            if (_intentName == "ScannerStatusIntent")
            {
                message += ship.ScannerCount > 0 ? $"The number of locked threats on our scanners is {ship.ScannerCount}. " : "There are no locked threats on our scanners. ";
            }
            if (_intentName == "ShipStatusIntent" || _intentName == "ShipHealthStatusIntent")
            {
                message += $"We have {ship.Shields} out of {ship.MaxShields} shields, and {ship.Hull} out of {ship.MaxHull} hull. ";
            }

            message += "What are your orders, captain? ";

            game.Message = message;

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("To assign your tactical crew to the weapons, you need to start a new game. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("That is not a valid action. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Tactical && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available tactical crew to fire weapons. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (game.ThreatManager.ExternalThreats.Count < 1)
            {
                return(ResponseCreator.Ask("Our scanners do not show any external threats at the moment. There is no need to assign tactical crew to the weapon systems. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if enemy target is present
            var request                = (IntentRequest)information.SkillRequest.Request;
            int tacticalCount          = request.Intent.Slots["NumberOfUnits"].ExtractNumber();
            int availableTacticalCount = ship.Crew.Count(c => c.Type == CrewType.Tactical && c.State == CrewState.Available);

            if (tacticalCount < 1 || tacticalCount > availableTacticalCount)
            {
                return(ResponseCreator.Ask($"You can assign up to {availableTacticalCount} tactical crew. Try the assign tactical crew command again and provide a valid number. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // we have valid tactical count, assign them
            ship.AssignTacticalToWeapons(tacticalCount);
            game.Message += $"Say fire weapons and  choose one of the following targets: {game.ThreatManager.GetThreatsAsString(false, true)}. ";
            // set game state to Firing Weapons
            game.GameState = GameState.FiringWeapons;

            game.RepeatMessage   = game.Message;
            game.RepromptMessage = $"We are in combat, captain! We can deal up to {ship.DamagePool} damage. Awaiting your orders to fire the weapons! We can fire the weapons at the following: {game.ThreatManager.GetThreatsAsString()}. ";
            game.SaveData();

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
예제 #13
0
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You can ask for more time when you're playing the game. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }
            string message = "When ready, say Alexa to issue your next command. ";

            message += SoundFx.MoreTime();;

            string reprompt = "If you need more time, say more time. ";

            game.Message = message;

            return(ResponseCreator.Ask(game.Message, reprompt, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before recharging your shields. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("This ship cannot recharge the shields. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Science && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available science crew to recharge the shields. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ShipSystems["ScienceUnavailable"])
            {
                return(ResponseCreator.Ask("Our science crew are having an existentialism crisis and are unavailable. Send a science crew on a mission to deal with cosmic existentialism to be able to use them again. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ShipSystems["ShieldsOffline"])
            {
                return(ResponseCreator.Ask("Our shields are offline and cannot be recharged. This is caused by the Nebula we are in. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (ship.Shields == ship.MaxShields)
            {
                return(ResponseCreator.Ask("Our shields are already at  maximum power, there is no need to recharge them. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // we are good to go, recharge the shields
            ship.RechargeShields();

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (game.RuleSelector <= 0)
            {
                return(ResponseCreator.Ask("You are at the beginning of the rules. Say next to continue. You can say new game at any point to start a new game. ", "Say next to continue to the next rule, or new game to start a new game. ", information.SkillRequest.Session));
            }


            game.RuleSelector--;
            string message = Utilities.GetRule(game.RuleSelector);


            game.RepromptMessage = message;
            game.Message         = message;
            game.RepeatMessage   = message;
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before repairing your ship. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("This ship cannot be repaired. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Engineering && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available engineering crew to repair the hull. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ShipSystems["EngineeringUnavailable"])
            {
                return(ResponseCreator.Ask("Our engineering crew is incapacitated from the panel explosion and cannot be used. Send a medical crew member on a mission to deal with the panel explosion. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (ship.Hull == ship.MaxHull)
            {
                return(ResponseCreator.Ask("The ship's hull has not sustained any damage  yet. There is nothing to repair at the moment. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // we are good to go, repair the hull
            ship.RepairShip();

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("To get information about the current active threats, you need to start a new game. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }


            var    threatManager = game.ThreatManager;
            string message       = "";

            message += threatManager.InternalThreats.Count > 0 ? $"Number of active internal threats is {threatManager.InternalThreats.Count}. {threatManager.GetThreatsAsString(true, false)}. " : "";
            message += threatManager.ExternalThreats.Count > 0 ? $"Number of active external threats is {threatManager.ExternalThreats.Count}. {threatManager.GetThreatsAsString(false, true)}. " : "";
            message += threatManager.ExternalThreats.Count + threatManager.InternalThreats.Count < 1 ? "There are no active threats at the moment. " : "";
            message += threatManager.ThreatDeck.Count > 0 ? $"Number of threats remaining in the threat deck is {threatManager.ThreatDeck.Count}. " : "There are no more cards in the threat deck. Destroy all external threats to win! ";

            message += "What are your orders, captain? ";

            game.Message = message;

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
예제 #18
0
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before sending your crew on a mission. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship;

            if (ship.AvailableCrewCount < 1)
            {
                return(ResponseCreator.Ask("We have no available crew to send on a mission. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if source crew type is available and present
            var    request     = (IntentRequest)information.SkillRequest.Request;
            string crewName    = request.Intent.Slots["Crew"].Value;
            bool   isCrewValid = Enum.TryParse(crewName.FirstCharToUpper(), out CrewType crewType);

            if (!isCrewValid)
            {
                return(ResponseCreator.Ask($"{crewName} is not a valid crew type. Try the send crew on a mission command again and provide one of the following  types: Tactical, Medical, Engineering, Science, or Commander. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // valid crew provided, check if iti s available
            CrewDie crewDie = ship.Crew.FirstOrDefault(c => c.Type == crewType && c.State == CrewState.Available);

            if (crewDie == null)
            {
                return(ResponseCreator.Ask($"{crewName} crew is not available. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // if crew is commander and comms are offline, commander can't go on a mission
            if (crewDie.Type == CrewType.Commander && ship.ShipSystems["CommsOffline"])
            {
                return(ResponseCreator.Ask("Our comms are offline. We cannot use our commander crew until you send an engineer on a mission to fix the communication systems. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (crewDie.Type == CrewType.Engineering && ship.ShipSystems["EngineeringUnavailable"])
            {
                return(ResponseCreator.Ask("Our engineering crew is incapacitated from the panel explosion and cannot be used. Send a medical crew member on a mission to deal with the panel explosion. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // we have a valid available crew die to send on a mission
            // check the threat
            if (!game.ThreatManager.ExternalThreats.Any(t => t.HasMission) && !game.ThreatManager.InternalThreats.Any(t => t.HasMission))
            {
                return(ResponseCreator.Ask("There are no threats with missions at the moment. Use this command when you encounter threats with missions. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if enemy target is present
            string threatId = request.Intent.Slots["Threat"].GetSlotId();
            var    threat   = game.ThreatManager.ExternalThreats.FirstOrDefault(t => t.Id == threatId) as Threat;

            if (threat == null)
            {
                // check internal threats
                threat = game.ThreatManager.InternalThreats.FirstOrDefault(t => t.Id == threatId) as Threat;
                if (threat == null)
                {
                    string threatName = request.Intent.Slots["Threat"].Value;

                    return(ResponseCreator.Ask($"{threatName} is not a valid target. Try sending your crew on a mission again and provide one of the following: {game.ThreatManager.GetThreatsAsString(true, true, true)}. ", game.RepromptMessage, information.SkillRequest.Session));
                }
            }
            // we have a valid target, check if it has missions
            if (!threat.HasMission)
            {
                return(ResponseCreator.Ask($"{threat.Name} cannot be dealt with by sending crew on a mission. Use this command again and provide one of the following: {game.ThreatManager.GetThreatsAsString(true, true, true)}. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // target has mission, check if we can assign this crew type
            // TODO: list the possible mission crew types for this threat in the response
            if (!threat.AwayMissions.Any(a => a.Type == crewDie.Type))
            {
                return(ResponseCreator.Ask($"You cannot send {crewName} on a mission to deal with {threat.Name}. Try this command again and provide a different crew type. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // valid crew type for this threat selected
            // check if all the slots are filled for this type
            if (!threat.AwayMissions.Any(a => a.Type == crewDie.Type && !a.IsAssigned))
            {
                return(ResponseCreator.Ask($"You have already assigned the required number of {crewName} crew to {threat.Name}. Try sending a different crew type on a mission to deal with this threat. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // check if science was sent on a mission while cosmic existentialism is active
            if (crewDie.Type == CrewType.Science && ship.ShipSystems["ScienceUnavailable"])
            {
// science sent on mission while cosmic existentialism is active
// check if the mission is cosmic existentialism
                if (threat.Id != "CE")
                {
                    return(ResponseCreator.Ask("Our science crew are having an existentialism crisis and are unavailable. Send a science crew on a mission to deal with cosmic existentialism to be able to use them again. ", game.RepromptMessage, information.SkillRequest.Session));
                }
            }


            // we're good, assign this crew type to this threat
            ship.SendCrewOnMission(crewDie, threat);

            // check if mission complete and process cleanup
            if (game.ThreatManager.CheckIfMissionComplete(threat))
            {
                ship.CompleteMission(threat);
                game.Message += $"Mission complete! {threat.Name} is no longer a threat to our ship. ";
            }
            else
            {
                game.Message += $"You sent one {crewName} crew on a mission to deal with the {threat.Name}. ";
            }

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            return(ResponseCreator.Ask(game.RepeatMessage, game.RepromptMessage, information.SkillRequest.Session));
        }
예제 #20
0
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before returning crew from a mission. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship;

            if (ship.MissionCrewCount < 1)
            {
                return(ResponseCreator.Ask("We currently do not have any crew members that are sent on a mission. You can use this command when you have crew members that are sent on missions. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if source crew type is available and present
            var    request     = (IntentRequest)information.SkillRequest.Request;
            string crewName    = request.Intent.Slots["Crew"].Value;
            bool   isCrewValid = Enum.TryParse(crewName.FirstCharToUpper(), out CrewType crewType);

            if (!isCrewValid)
            {
                return(ResponseCreator.Ask($"{crewName} is not a valid crew type. Try the send crew on a mission command again and provide one of the following  types: Tactical, Medical, Engineering, Science, or Commander. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // valid crew provided, check if iti s on a mission



            // check the threat
            if (game.ThreatManager.ExternalThreats.Count < 1 && game.ThreatManager.InternalThreats.Count < 1)
            {
                return(ResponseCreator.Ask("There are no threats at the moment. This shouldn't have happened, please report this to the developer. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if enemy target is present
            string threatId = request.Intent.Slots["Threat"].GetSlotId();
            var    threat   = game.ThreatManager.ExternalThreats.FirstOrDefault(t => t.Id == threatId) as Threat;

            if (threat == null)
            {
                // check internal threats
                threat = game.ThreatManager.InternalThreats.FirstOrDefault(t => t.Id == threatId) as Threat;
                if (threat == null)
                {
                    string threatName = request.Intent.Slots["Threat"].Value;
                    // TODO: Show threats with missions only.
                    return(ResponseCreator.Ask($"{threatName} is not a valid target. Try the return crew from a mission command again and provide a different target. ", game.RepromptMessage, information.SkillRequest.Session));
                }
            }
            // we have a valid target, check if it has missions
            if (!threat.HasMission)
            {
                return(ResponseCreator.Ask($"{threat.Name} is not a valid threat. Try the return crew from a mission command again and provide a different threat. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // target has mission, check if we can assign this crew type


            CrewDie crewDie = ship.Crew.FirstOrDefault(c => c.Type == crewType && c.State == CrewState.Mission && c.MissionName == threat.Name);

            if (crewDie == null)
            {
                return(ResponseCreator.Ask($"We do not have any {crewName} crew assigned on a mission to deal with {threat.Name}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // check if all the slots are filled for this type
            if (!threat.AwayMissions.Any(a => a.Type == crewDie.Type && a.IsAssigned))
            {
                return(ResponseCreator.Ask($"There are no {crewName} crew assigned to {threat.Name}. Use the return crew from mission command again and provide a valid crew type and threat. ", game.RepromptMessage, information.SkillRequest.Session));
            }


            // we're good, return crew from this threat
            ship.ReturnCrewFromMission(crewDie, threat);



            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before firing your weapons. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("That is not a valid action. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (game.GameState != GameState.FiringWeapons)
            {
                return(ResponseCreator.Ask($"You need to assign tactical crew to the weapons to fire them. Say assign tactical crew to weapons to do that. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // check if enemy target is present
            var    request  = (IntentRequest)information.SkillRequest.Request;
            string threatId = request.Intent.Slots["ExternalThreat"].GetSlotId();
            var    threat   = game.ThreatManager.ExternalThreats.FirstOrDefault(t => t.Id == threatId);

            if (threat == null)
            {
                string threatName = request.Intent.Slots["ExternalThreat"].Value;
                return(ResponseCreator.Ask($"{threatName} is not a valid target. Try firing weapons again and provide one of the following: {game.ThreatManager.GetThreatsAsString(false, true)}. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // let's check the damage amount
            int damage = request.Intent.Slots["DamageAmount"].ExtractNumber();

            if (damage < 1 || damage > ship.DamagePool)
            {
                return(ResponseCreator.Ask($"Please provide a valid damage amount. You can deal up to {ship.DamagePool} damage. Say fire weapons to try again. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // damage amount is correct, open fire!
            bool canFireAgain = ship.FireWeapons(threat, damage);

            // first check if we are dead after destroying threat, some threats may cause damage to use when they die
            if (game.IsShipDestroyed())
            {
                game.GameOver();
                game.SaveData();
                return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
            }

            if (canFireAgain && game.ThreatManager.ExternalThreats.Count > 0)
            {
                game.Message        += $"We have {ship.DamagePool} more damage to spend. Say fire weapons again and  choose one of the following targets: {game.ThreatManager.GetThreatsAsString(false, true)}. ";
                game.RepeatMessage   = game.Message;
                game.RepromptMessage = $"Our tactical crew is waiting for your orders to open fire. We need to spend {ship.DamagePool} more damage. Say fire weapons and provide one of the following targets: {game.ThreatManager.GetThreatsAsString(false, true)}. ";
                game.SaveData();
                return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
            }
            // we're either out of damage to spend or  there are no more threats
            // go back to player turn state
            game.GameState = GameState.PlayerTurn;
            if (ship.DamagePool < 1)
            {
                game.Message += "All weapons fired, captain. Awaiting further orders. ";
            }
            else if (game.ThreatManager.ExternalThreats.Count < 1)
            {
                game.Message += "All external threats destroyed! Awaiting further orders, sir. ";
            }
            ship.DamagePool      = 0;
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "What are your orders, sir? ";
            game.SaveData();

            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }
        public override SkillResponse HandleSyncRequest(AlexaRequestInformation <SkillRequest> information)
        {
            var game = (Game)information.Context;

            if (!game.IsGameInProgress)
            {
                return(ResponseCreator.Ask("You need to start a new game before transforming your crew. Say new game to begin. ", "To start, say new game. ", information.SkillRequest.Session));
            }

            var ship = game.Ship as HalcyonShip;

            if (ship == null)
            {
                return(ResponseCreator.Ask("That is not a valid command for this ship. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            if (!ship.Crew.Any(c => c.Type == Enums.CrewType.Commander && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"We have no available commander to transform crew. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.ShipSystems["CommsOffline"])
            {
                return(ResponseCreator.Ask("Our comms are offline. We cannot use our commander crew until you send an engineer on a mission to fix the communication systems. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            if (ship.AvailableCrewCount < 2)
            {
                return(ResponseCreator.Ask("There are no other available crew members to transform. ", game.RepromptMessage, information.SkillRequest.Session));
            }
            // check if source crew type is available and present
            var    request        = (IntentRequest)information.SkillRequest.Request;
            string sourceCrewName = request.Intent.Slots["SourceCrew"].Value;
            bool   isSourceValid  = Enum.TryParse(sourceCrewName.FirstCharToUpper(), out CrewType sourceCrew);

            if (!isSourceValid)
            {
                return(ResponseCreator.Ask($"{sourceCrewName} is not a valid crew type. Try the transform crew command again and provide one of the following  types: Tactical, Medical, Engineering, Science, or Commander. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // check if source is commander, and there is no second commander to transform
            if (sourceCrew == CrewType.Commander && ship.Crew.Count(c => c.Type == CrewType.Commander && c.State == CrewState.Available) < 2)
            {
                return(ResponseCreator.Ask($"You do not have another commander that you can transform into a different crew type. A commander cannot transform itself into a different crew type. Try the transform command again and provide a different crew type. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // valid source crew provided, let's check if it is available in our crew
            if (!ship.Crew.Any(c => c.Type == sourceCrew && c.State == CrewState.Available))
            {
                return(ResponseCreator.Ask($"{sourceCrewName} crew is not available. We have {ship.GetAvailableCrewAsString()}. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // source is valid, let's check the target now
            string targetCrewName = request.Intent.Slots["TargetCrew"].Value;
            bool   isTargetValid  = Enum.TryParse(targetCrewName.FirstCharToUpper(), out CrewType targetCrew);

            if (!isTargetValid)
            {
                return(ResponseCreator.Ask($"{targetCrewName} is not a valid crew type to transform to. Try the transform crew command again and provide one of the following  types: Tactical, Medical, Engineering, Science, or Commander. ", game.RepromptMessage, information.SkillRequest.Session));
            }

            // finally let's check if source is equal to target
            if (sourceCrew == targetCrew)
            {
                return(ResponseCreator.Ask($"You cannot transform {sourceCrewName} to {targetCrewName}. Try the command again and provide a different crew type to transform to. ", game.RepromptMessage, information.SkillRequest.Session));
            }


            // we are all good, transform the crew!
            ship.TransformCrew(sourceCrew, targetCrew);

            game.Message        += "Awaiting further orders, captain. ";
            game.RepeatMessage   = game.Message;
            game.RepromptMessage = "Waiting for further orders, captain. ";
            game.SaveData();
            return(ResponseCreator.Ask(game.Message, game.RepromptMessage, information.SkillRequest.Session));
        }