예제 #1
0
        public async Task <HasActionsLeft> DoInventoryAction(string category, string name, string action, bool dryRun = false)
        {
            await GoBackIfInStorylet();

            var item = await _session.GetPossession(category, name);

            if (item != null && item.effectiveLevel >= 1)
            {
                var result = await _session.UseQuality(item.id);

                if (result.isSuccess && !dryRun)
                {
                    _cachedList = null;
                    var hasActionsLeft = await PerformAction(action);                     // performaction defaults to available, until we figure out phase for storyletlist, handle this manually

                    if (hasActionsLeft == HasActionsLeft.Available)
                    {
                        return(HasActionsLeft.Consumed);
                    }
                    else
                    {
                        return(hasActionsLeft);
                    }
                }
                // todo the following two could possibly be thrown instead
                return(HasActionsLeft.Faulty);        // usequality failed
            }
            return(HasActionsLeft.Faulty);            // we don't actually have that possession, some prereq failed
        }
예제 #2
0
        public async Task <HasActionsLeft> ActivateOpportunityCard(CardAction card)
        {
            if (card.eventId == null)
            {
                throw new Exception("card has no eventId set");
            }
            if (_cachedOpportunity == null || _cachedOpportunity.isInAStorylet)
            {
                await _session.GoBack();
            }

            Log.Info($"doing card {card.name} action {card.action}");
            _cachedList = await _session.BeginStorylet(card.eventId.Value);

            if (!string.IsNullOrWhiteSpace(card.action))
            {
                return(await PerformActions(card.action.Split(',')));
            }
            else
            {
                _cachedList.LogMessages();
            }

            return(HasActionsLeft.Consumed);
        }
예제 #3
0
        public async Task <HasActionsLeft> PerformAction(string name)
        {
            if (_cachedList == null || _cachedList.phase == "End")
            {
                _cachedList = await _session.ListStorylet();
            }
            if (_cachedList.phase == "Act")
            {
                var branchId = _cachedList.socialAct.inviteeData.branchId;
                var friend   = _cachedList.socialAct.inviteeData.eligibleFriends.SelectFriend(name);
                _cachedList = await _session.SendInternalSocialAct(branchId, friend.id);

                return(HasActionsLeft.Consumed);
            }
            if (_cachedList.phase == "Available")
            {
                throw new Exception($"Trying to perform action {name} while phase: Available");
            }
            var branch = _cachedList.storylet.childBranches.GetChildBranch(name);

            if (branch == null)
            {
                return(HasActionsLeft.Faulty);
            }

            var branchResult = await _session.ChooseBranch(branch.id);

            if (branchResult != null)
            {
                _cachedList = branchResult;
            }

            return(HasActionsLeft.Available);            // can technically be consumed, but until we figure out list.phase and stuff, we have to depend on upstream calls knowing what they are doing
        }
예제 #4
0
        public async Task MoveIfNeeded(string location)
        {
            if (string.Equals("any", location, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            if (await _session.IsInLocation(location))
            {
                return;
            }

            if (await _session.GetLocationId(location) == await _session.GetLocationId("empress court"))
            {
                //todo require route shuttered plaace
                await _session.MoveTo("shutteredpalace");

                _cachedList = await _session.ListStorylet();
                await EnterStorylet("spend");
                await PerformAction("1");

                _cachedList = await _session.ListStorylet();

                return;
            }

            // todo test if race condition since we throw away result from moveto?
            await _session.MoveTo(location);

            _cachedList = await _session.ListStorylet();
        }
예제 #5
0
        public async Task GoBackIfInStorylet()
        {
            if (_cachedList == null || _cachedList.phase == "End")
            {
                _cachedList = await _session.ListStorylet();
            }
            if (_cachedList.phase == "Available")
            {
                return;
            }

            if (_cachedList.storylet == null)
            {
                return;
            }

            if (_cachedList.storylet.canGoBack.HasValue && _cachedList.storylet.canGoBack.Value)
            {
                Log.Debug("DEBUG: exiting storylet");
                _cachedList = await _session.GoBack();

                return;
            }
            else
            {
                //          # we check for this much earlier, this is redundant. Also it is a forced action, not locked storylet
                //          $done = HandleLockedStorylet $list
                //          return $null
                throw new Exception("called GoBackIfInStorylet on what looks like locked storylet");
            }
        }
예제 #6
0
 public async Task <bool> HasForcedAction()
 {
     if (_cachedList == null)
     {
         _cachedList = await _session.ListStorylet();
     }
     return(_cachedList.phase != "Available" && _cachedList.storylet != null && (_cachedList.storylet.canGoBack.HasValue && !_cachedList.storylet.canGoBack.Value));
 }
예제 #7
0
 public async Task <string> GetStoryletName()
 {
     if (_cachedList == null)
     {
         _cachedList = await _session.ListStorylet();
     }
     return(_cachedList.storylet?.name);
 }
예제 #8
0
        public async Task <StoryletList> BeginStorylet(long id)
        {
            StoryletList ev = await Post <StoryletList>("storylet/begin", new { eventId = id });

            if (ev.storylet != null)
            {
                Log.Info($"BeginStorylet: {ev.storylet.name} -> {ev.storylet.description}");
            }
            return(ev);
        }
예제 #9
0
 public static void LogMessages(this StoryletList list)
 {
     if (list.endStorylet != null)
     {
         fl.Log.Info($"EndStorylet: {list.endStorylet.eventValue.name} -> {list.endStorylet.eventValue.description}");
     }
     if (list.messages != null && list.messages.defaultMessages != null)
     {
         foreach (var m in list.messages.defaultMessages)
         {
             fl.Log.Info($"message: {m.message}");
         }
     }
 }
예제 #10
0
        public async Task <StoryletList> ChooseBranch(long id)
        {
            if (TestModeEnabled)
            {
                TestPostedBranches.Add(id);
                return(null);
            }
            else
            {
                StoryletList ev = await Post <StoryletList>("storylet/choosebranch", new { branchId = id, secondChanceIds = new int[0] });

                ev.LogMessages();
                return(ev);
            }
        }
예제 #11
0
        // returned bool here is an IsSuccess flag, not hasactionsleft
        // it isnt used afaict, so just throw on error?
        public async Task <bool> EnterStorylet(string storyletname)
        {
            var sid = await _session.GetStoryletId(storyletname, _cachedList);

            if (sid != null)
            {
                _cachedList = await _session.BeginStorylet(sid.Value);

                return(true);
            }
            else
            {
                _cachedList = null;
                return(false);
            }
        }
예제 #12
0
        public async Task <HasActionsLeft> SocialInteraction(long id)
        {
            await _session.BeginSocialEvent(id);

            _cachedList = await _session.ListStorylet();

            var action = SocialEventsHandler.GetActionFor(_cachedList.storylet.name);

            if (action == null)
            {
                // todo add discard message here
                return(HasActionsLeft.Available);
            }

            Log.Info($"Doing interaction {_cachedList.storylet.name}");
            return(await PerformActions(action.Split(',')));
        }
예제 #13
0
        public async Task <HasActionsLeft> PerformActions(IEnumerable <string> actions)
        {
            if (actions == null)
            {
                return(HasActionsLeft.Faulty);                // todo throw exception here?
            }
            foreach (var action in actions)
            {
                if (!string.IsNullOrWhiteSpace(action))
                {
                    if (_cachedList.phase == "End")
                    {
                        _cachedList = await _session.ListStorylet();
                    }
                    var result = await PerformAction(action);

                    if (_cachedList == null || result == HasActionsLeft.Faulty)
                    {
                        return(HasActionsLeft.Faulty);
                    }
                }
            }
            return(HasActionsLeft.Consumed);
        }
예제 #14
0
        public static async Task <long?> GetStoryletId(this Session s, string name, StoryletList list = null)
        {
            if (list == null)
            {
                list = await s.ListStorylet();
            }
            var n = name.AsNumber();

            if (n != null)
            {
                return(list.storylets[n.Value - 1].id);
            }

            var r = new Regex(name, RegexOptions.IgnoreCase);

            foreach (var item in list.storylets)
            {
                if (r.IsMatch(item.name))
                {
                    return(item.id);
                }
            }
            return(null);
        }
예제 #15
0
 // for testing
 public static StoryletList AsDryrun(this StoryletList list, string message)
 {
     return(new StoryletList {
         phase = message, isSuccess = list.isSuccess
     });
 }