Esempio n. 1
0
        public void CampActionValidInWilderness()
        {
            actor.Enter <Location>(wilderness);
            var action = new CampAction(actor);

            Assert.AreEqual(ActionOutcome.Progress(), action.Execute(dryRun: true));
        }
Esempio n. 2
0
        public async Task <ActionOutcome> WellActionOutcome(Well well, Models.Action action, CancellationToken cancellationToken)
        {
            var request = new GraphQLRequest();

            request.Variables = new { wellId = well.id, actionId = action.id };
            request.Query     = @" query($wellId: ID, $actionId: ID){
                actionOutcomeFilter(filters: [
                    {
                        fieldName: ""well""
                        op: ""==""
                        value: { ID: $wellId }
                    }
                    {
                        fieldName: ""action""
                        op: ""==""
                        value: { ID: $actionId }
                    }
                ]) 
                {
                    id
                    action {
                        id
                        name
                        type
                    }
                    well {
                        id
                        name
                    }
                    probabilityOfAnomaly
                    cost
                    manHours
                    increaseInOilRate
                }
            }";

            var response = await Client.GetClientInstance().PostAsync(request);

            var outcomes = response.GetDataFieldAs <List <ActionOutcome> >("actionOutcomeFilter");

            ActionOutcome actionOutcome;

            if (outcomes != null && outcomes.Count > 0)
            {
                actionOutcome = outcomes.First();
            }
            else
            {
                actionOutcome        = new ActionOutcome();
                actionOutcome.id     = "1";
                actionOutcome.action = action;
                actionOutcome.well   = well;
                actionOutcome.probabilityOfAnomaly = 0;
                actionOutcome.cost              = 0;
                actionOutcome.manHours          = 0;
                actionOutcome.increaseInOilRate = 0;
            }
            return(actionOutcome);
        }
 public static ExecutionResult Result <TCommand, TUser, TResult>(
     this ICommandHandler <TCommand, TUser> handler,
     TResult content,
     ActionOutcome actionOutcome)
     where TCommand : ICommand
 {
     return(ExecutionResult.Create(content, actionOutcome));
 }
Esempio n. 4
0
        public void Meditate()
        {
            Player <DummyEntity> player = new(verbSuite, new SpyPlayerIO(new()
            {
                "meditate"
            }));

            ActionOutcome outcome = player.Act(PLAYER);

            Assert.AreEqual("entity#1.meditate()", outcome.Message);
        }
Esempio n. 5
0
 public void Execute(string[] cmdTokens)
 {
     try
     {
         ProcessCommand(cmdTokens);
     }
     catch (Exception)
     {
         var failedOutcome = new ActionOutcome(OutcomeStatus.Fail, "The command input is invalid");
         _callStack.Push(new Call(this, failedOutcome));
     }
 }
Esempio n. 6
0
        public PlayerTests()
        {
            System.Func <string, IGameAction> ok = (string m) => ActionOutcome.Success(m).AsAction();
            var verbList = new List <IVerb <DummyEntity> >()
            {
                new ZeroTargetVerb <DummyEntity>((e) => ok($"entity#{e}.meditate()"), "meditate"),
                new SingleTargetVerb <DummyEntity>(DummyLookup, (e, t) => ok($"entity#{e}.contemplate(entity#{t})"), "contemplate"),
                new SingleTargetVerbWithTool <DummyEntity>(DummyLookup, (e, v, t) => ok($"entity#{e}.shave(entity#{v}, entity#{t})"), "shave"),
            };

            verbSuite = new(verbList);
        }
Esempio n. 7
0
        public void CanCampInWilderness()
        {
            actor.Enter <Location>(wilderness);
            var action = new CampAction(actor);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(ActionOutcome.Progress(), action.Execute(dryRun: false));
            }
            Assert.IsFalse(wilderness.Get <Wilderness>().HasCampsite);
            Assert.AreEqual(ActionOutcome.Success(), action.Execute(dryRun: false));
            Assert.IsTrue(wilderness.Get <Wilderness>().HasCampsite);
        }
Esempio n. 8
0
        public void TakeTest()
        {
            GameObject place = new GameObject();
            GameObject prop  = new GameObject(place);

            prop.AddTrait(new InventoryItem(weight: 1));
            PhysicalActor actor = new PhysicalActor(new FakeBody(), place);
            Take          take  = new Take {
                Actor = actor, Target = prop
            };
            ActionOutcome outcome = take.Attempt();

            Assert.IsTrue(outcome.Success());
            Assert.AreEqual(actor, prop.Location);
        }
        public async Task QueryResult_ReturnsStatusCodeOnly_IfStatusCodeHasNoBody(int statusCode)
        {
            // Arrange
            var command           = new TestQuery();
            var actionOutcome     = new ActionOutcome("foobar", statusCode, true);
            var executionResponse = ExecutionResponse.Create("the result", actionOutcome, null);
            var invoker           = A.Fake <IQueryInvoker>();

            A.CallTo(() => invoker.Invoke(command, null))
            .Returns(executionResponse);

            var controller = new TestQueryController(invoker);

            // Act
            var result = await controller.CallQuery(command);

            // Assert
            result.Should().BeOfType <StatusCodeResult>().Which.StatusCode.Should().Be(statusCode);
        }
 public MockPreparedAction(ActionOutcome scriptedDryRunOutcome, ActionOutcome scriptedActualOutcome, uint prepartionNeeded)
 {
     this.scriptedDryRunOutcome = scriptedDryRunOutcome;
     this.scriptedActualOutcome = scriptedActualOutcome;
     this.preparationNeeded     = prepartionNeeded;
 }
Esempio n. 11
0
        public async Task <ImportedCards> Import()
        {
            ProtoCollection collection;

            if (remoteCollectionFirst)
            {
                try {
                    collection = await new GoogleSheetsCollection().Fetch();
                }
                catch (Exception e) when(e is WebException || e is FormatException)
                {
                    Debug.LogError("[CollectionImporter] Import from Google Sheets failed: " + e.Message);
                    Debug.LogWarning("[CollectionImporter] Trying local collection...");
                    collection = LocalCollection.Fetch();
                    if (collection.cards.Count == 0)
                    {
                        Debug.LogWarning("[CollectionImporter] Import from local collection returned 0 cards");
                    }
                }
            }
            else
            {
                collection = LocalCollection.Fetch();
                if (collection.cards.Count == 0)
                {
                    Debug.LogWarning("[CollectionImporter] Import from local collection returned 0 cards, "
                                     + "trying Google Sheets...");
                    try {
                        collection = await new GoogleSheetsCollection().Fetch();
                    }
                    catch (Exception e) when(e is WebException || e is FormatException)
                    {
                        Debug.LogError("[CollectionImporter] Import from Google Sheets failed: " + e.Message);
                    }
                }
            }

            Dictionary <int, Sprite> sprites = new Dictionary <int, Sprite>();

            foreach (ProtoImage image in collection.images)
            {
                if (sprites.ContainsKey(image.id))
                {
                    Debug.LogWarning("[CollectionImporter] Duplicate id found in Images");
                    continue;
                }
                if (image.url == null)
                {
                    Debug.LogWarning("[CollectionImporter] Image (id: " + image.id + ") has a null URL");
                    continue;
                }

                Debug.Log("[CollectionImporter] Fetching image from " + image.url + " ...");
                HttpWebResponse imageResponse;
                try {
                    HttpWebRequest imageRequest = WebRequest.CreateHttp(image.url);
                    imageResponse = (HttpWebResponse)await imageRequest.GetResponseAsync();
                }
                catch (WebException e) {
                    Debug.LogError("[CollectionImporter] Request failed: " + e.Message);
                    continue;
                }

                if (imageResponse.StatusCode != HttpStatusCode.OK)
                {
                    Debug.LogWarning(
                        "[CollectionImporter] "
                        + image.url
                        + ": "
                        + (int)imageResponse.StatusCode
                        + " "
                        + imageResponse.StatusDescription);
                    continue;
                }

                Stream imageStream;
                if ((imageStream = imageResponse.GetResponseStream()) == null)
                {
                    Debug.LogWarning(
                        "[CollectionImporter] Remote host returned no image in response (URL: "
                        + image.url
                        + ")");
                    continue;
                }

                byte[]    imageData = Util.BytesFromStream(imageStream);
                Texture2D texture   = new Texture2D(1, 1);
                if (!texture.LoadImage(imageData))
                {
                    Debug.LogWarning(
                        "[CollectionImporter] Could not create sprite texture from image (URL: "
                        + image.url
                        + ")");
                    continue;
                }

                Sprite sprite = Sprite.Create(
                    texture,
                    new Rect(0.0f, 0.0f, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f));
                sprites.Add(image.id, sprite);
            }

            Dictionary <int, Character> characters = new Dictionary <int, Character>();

            foreach (ProtoCharacter protoCharacter in collection.characters)
            {
                if (characters.ContainsKey(protoCharacter.id))
                {
                    Debug.LogWarning("[CollectionImporter] Duplicate id found in Characters");
                    continue;
                }
                Character character = new Character(protoCharacter.name, defaultSprite);
                sprites.TryGetValue(protoCharacter.imageId, out character.sprite);
                characters.Add(protoCharacter.id, character);
            }

            Dictionary <int, Card> cards = new Dictionary <int, Card>();

            foreach (ProtoCard protoCard in collection.cards)
            {
                if (cards.ContainsKey(protoCard.id))
                {
                    Debug.LogWarning("[CollectionImporter] Duplicate id found in Cards");
                    continue;
                }

                IFollowup   leftActionFollowup = null;
                ProtoAction leftAction         = protoCard.leftAction;
                if (leftAction.followup != null && leftAction.followup.Count > 0)
                {
                    if (leftAction.followup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") left action has more than one Followup");
                        continue;
                    }
                    leftActionFollowup = leftAction.followup[0];
                }
                if (leftAction.specialFollowup != null && leftAction.specialFollowup.Count > 0)
                {
                    if (leftAction.specialFollowup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") left action has more than one SpecialFollowup");
                        continue;
                    }
                    if (leftActionFollowup != null)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") left action has both types of followups");
                        continue;
                    }
                    leftActionFollowup = leftAction.specialFollowup[0];
                }

                IFollowup   rightActionFollowup = null;
                ProtoAction rightAction         = protoCard.rightAction;
                if (rightAction.followup != null && rightAction.followup.Count > 0)
                {
                    if (rightAction.followup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") right action has more than one Followup");
                        continue;
                    }
                    rightActionFollowup = rightAction.followup[0];
                }
                if (rightAction.specialFollowup != null && rightAction.specialFollowup.Count > 0)
                {
                    if (rightAction.specialFollowup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") right action has more than one SpecialFollowup");
                        continue;
                    }
                    if (rightActionFollowup != null)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] Card (id: "
                            + protoCard.id
                            + ") right action has both types of followups");
                        continue;
                    }
                    rightActionFollowup = rightAction.specialFollowup[0];
                }

                ActionOutcome leftActionOutcome  = new ActionOutcome(leftAction.statsModification, leftActionFollowup);
                ActionOutcome rightActionOutcome = new ActionOutcome(rightAction.statsModification, rightActionFollowup);

                List <ICardPrerequisite> prerequisites = new List <ICardPrerequisite>();

                bool failed = false;
                foreach (ProtoCardPrerequisite prereq in protoCard.cardPrerequisites)
                {
                    CardPrerequisite cardPrerequisite = new CardPrerequisite(prereq.id);
                    try {
                        foreach (string s in prereq.status)
                        {
                            cardPrerequisite.Status |= CardStatusFor(s);
                        }
                    }
                    catch (ArgumentException e) {
                        Debug.LogWarning("[CollectionImporter] Card (id: " + protoCard.id + "): " + e.Message);
                        failed = true;
                        break;
                    }
                    prerequisites.Add(cardPrerequisite);
                }
                if (failed)
                {
                    continue;
                }

                foreach (ProtoSpecialCardPrerequisite prereq in protoCard.specialCardPrerequisites)
                {
                    SpecialCardPrerequisite cardPrerequisite = new SpecialCardPrerequisite(prereq.id);
                    try {
                        foreach (string s in prereq.status)
                        {
                            cardPrerequisite.Status |= CardStatusFor(s);
                        }
                    }
                    catch (ArgumentException e) {
                        Debug.LogWarning("[CollectionImporter] Card (id: " + protoCard.id + "): " + e.Message);
                        failed = true;
                        break;
                    }
                    prerequisites.Add(cardPrerequisite);
                }
                if (failed)
                {
                    continue;
                }

                Card card = new Card(
                    protoCard.cardText,
                    leftAction.text,
                    rightAction.text,
                    null,
                    leftActionOutcome,
                    rightActionOutcome,
                    prerequisites);

                characters.TryGetValue(protoCard.characterId, out card.character);

                cards.Add(protoCard.id, card);
            }

            Dictionary <string, SpecialCard> specialCards = new Dictionary <string, SpecialCard>();

            foreach (ProtoSpecialCard protoSpecialCard in collection.specialCards)
            {
                if (protoSpecialCard.id == null)
                {
                    Debug.LogWarning("[CollectionImporter] Null id found in SpecialCards");
                    continue;
                }
                if (specialCards.ContainsKey(protoSpecialCard.id))
                {
                    Debug.LogWarning("[CollectionImporter] Duplicate id found in SpecialCards");
                    continue;
                }

                IFollowup          leftActionFollowup = null;
                ProtoSpecialAction leftAction         = protoSpecialCard.leftAction;
                if (leftAction.followup != null && leftAction.followup.Count > 0)
                {
                    if (leftAction.followup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") left action has more than one Followup");
                        continue;
                    }
                    leftActionFollowup = leftAction.followup[0];
                }
                if (leftAction.specialFollowup != null && leftAction.specialFollowup.Count > 0)
                {
                    if (leftAction.specialFollowup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") left action has more than one SpecialFollowup");
                        continue;
                    }
                    if (leftActionFollowup != null)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") left action has both types of followups");
                        continue;
                    }
                    leftActionFollowup = leftAction.specialFollowup[0];
                }

                IFollowup          rightActionFollowup = null;
                ProtoSpecialAction rightAction         = protoSpecialCard.rightAction;
                if (rightAction.followup != null && rightAction.followup.Count > 0)
                {
                    if (rightAction.followup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") right action has more than one Followup");
                        continue;
                    }
                    rightActionFollowup = rightAction.followup[0];
                }
                if (rightAction.specialFollowup != null && rightAction.specialFollowup.Count > 0)
                {
                    if (rightAction.specialFollowup.Count > 1)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") right action has more than one SpecialFollowup");
                        continue;
                    }
                    if (rightActionFollowup != null)
                    {
                        Debug.LogWarning(
                            "[CollectionImporter] SpecialCard (id: "
                            + protoSpecialCard.id
                            + ") right action has both types of followups");
                        continue;
                    }
                    rightActionFollowup = rightAction.specialFollowup[0];
                }

                IActionOutcome leftActionOutcome  = null;
                IActionOutcome rightActionOutcome = null;

                if (protoSpecialCard.id == "gameover_coal" ||
                    protoSpecialCard.id == "gameover_food" ||
                    protoSpecialCard.id == "gameover_health" ||
                    protoSpecialCard.id == "gameover_hope")
                {
                    leftActionOutcome  = new GameOverOutcome();
                    rightActionOutcome = new GameOverOutcome();
                }

                SpecialCard specialCard = new SpecialCard(
                    protoSpecialCard.cardText,
                    leftAction.text,
                    rightAction.text,
                    null,
                    leftActionOutcome,
                    rightActionOutcome);

                characters.TryGetValue(protoSpecialCard.characterId, out specialCard.character);

                specialCards.Add(protoSpecialCard.id, specialCard);
            }

            return(new ImportedCards(cards, specialCards));
        }
Esempio n. 12
0
 private ExecutionResult(ActionOutcome actionOutcomeCode, object content)
 {
     this.ActionOutcomeCode = actionOutcomeCode;
     this.GetContent        = content;
 }
Esempio n. 13
0
 public static ExecutionResult Create <T>(T content, ActionOutcome actionOutcome)
 {
     return(new ExecutionResult(actionOutcome, content));
 }
Esempio n. 14
0
        public List <ActionFinancialEstimate> SkippingTestCostReduction(double oilPrice, Metrics measuredMetrics, ActionOutcome actionOutcome, CancellationToken cancellationToken)
        {
            var probabilityOfAnomaly           = actionOutcome.probabilityOfAnomaly / 100;
            var potentialCostOfSkippikingATest = measuredMetrics.oilRate * probabilityOfAnomaly * oilPrice * 60000;
            var costReduction = actionOutcome.cost;
            var manHours      = actionOutcome.manHours;

            var afe = new ActionFinancialEstimate
            {
                id       = Guid.NewGuid().ToString(),
                action   = actionOutcome.action,
                well     = actionOutcome.well,
                impact   = costReduction,
                cost     = potentialCostOfSkippikingATest,
                manHours = manHours
            };

            return(new List <ActionFinancialEstimate> {
                afe
            });
        }
Esempio n. 15
0
        public List <ActionFinancialEstimate> InterventionRevenueGain(double oilPrice, Metrics measuredMetrics, ActionOutcome actionOutcome, CancellationToken cancellationToken)
        {
            var increaseInOilRate = actionOutcome.increaseInOilRate;
            var cost     = actionOutcome.cost;
            var manHours = actionOutcome.manHours;

            // Oil rate is in thousand of barrels, and increase in oil rate is in percentage.
            var revenueIncrease = measuredMetrics.oilRate * oilPrice * 180000 * (increaseInOilRate / 100);

            var afe = new ActionFinancialEstimate
            {
                id       = Guid.NewGuid().ToString(),
                action   = actionOutcome.action,
                well     = actionOutcome.well,
                impact   = revenueIncrease,
                cost     = cost,
                manHours = manHours
            };

            return(new List <ActionFinancialEstimate>()
            {
                afe
            });
        }