public static PlayerActionEvents Map(this PlayerActionEvents toItems, ActionRequests fromItems, Actions actions)
        {
            toItems.Clear();

            foreach (var fromItem in fromItems)
            {
                toItems.Add(new PlayerActionEvent().Map(fromItem, actions));
            }

            return(toItems);
        }
 void Start()
 {
     animator = GetComponent<Animator>();
     events = transform.parent.gameObject.GetComponent<PlayerActionEvents>();
     events.moveDirectionChange += onMoveDirectionChange;
     //GetComponent<NetworkAnimator>().SetParameterAutoSend(0, true);
     if (!isLocalPlayer)
     {
         //GetComponent<RotateMatchPlayerMove>().enabled = false;
     }
 }
        public static PlayerActionEvents ValidateStep(
            this TriggerStep triggerStep,
            PlayerActionEvents currentPlayerActions,
            PlayerActionEvents participatingPlayerActions
            )
        {
            var stepPlayerActions = new PlayerActionEvents();

#pragma warning disable CS0219 // Variable is assigned but its value is never used
            bool contains;
#pragma warning restore CS0219 // Variable is assigned but its value is never used

            foreach (var action in currentPlayerActions)
            {
                foreach (var rule in triggerStep.ActionOccurrenceRules)
                {
                    if (
                        action.OccurredAt != null &&
                        rule.InsideOf.Contains(new Point(
                                                   new Coordinate(
                                                       action.OccurredAt.Coordinate.CoordinateValue.X,
                                                       action.OccurredAt.Coordinate.CoordinateValue.Y
                                                       )
                                                   )))
                    {
                        contains = true;

                        if (!stepPlayerActions.Exists(e => e.ActionRefId.Equals(action.ActionRefId)))
                        {
                            stepPlayerActions.Add(action);
                        }
                    }
                }
            }

            // logic to validate other than geofence

            // add stepPlayerActions to participatingPlayerActions
            foreach (var action in stepPlayerActions)
            {
                action.TriggerStepRefId = triggerStep.TriggerStepRefId;

                if (!participatingPlayerActions.Exists(e => e.ActionRefId.Equals(action.ActionRefId)))
                {
                    participatingPlayerActions.Add(action);
                }
            }

            return(participatingPlayerActions);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="goalTrigger"></param>
        /// <param name="playerActionEvents">The events to be considered by this Step</param>
        /// <returns></returns>
        public static PlayerActionEvents ValidateSteps(
            this GoalTrigger goalTrigger,
            PlayerActionEvents playerActionEvents
            )
        {
            var participatingActionEvents = new PlayerActionEvents();

            // process in order
            // each step, marks goalrefid in actions that are returned thus burning for next step
            foreach (var step in goalTrigger.Steps.OrderBy(e => e.ExecutionOrder))
            {
                try
                {
                    participatingActionEvents.AddRange(
                        step.ValidateStep(playerActionEvents, participatingActionEvents)
                        );

                    // if valid then which participatingActionEvents participated?

                    // if set to burn then add GoalTriggerRefId
                    participatingActionEvents.ForEach(e => e.TriggerStepRefId = goalTrigger.EntityRefId);

                    // if Step is valid then continue
                    continue;
                }
                catch (ArgumentException aex)
                {
                    return(new PlayerActionEvents());
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            // when all steps are valid the Goal is accomplished
            return(participatingActionEvents);
        }
        public void SingleActionAwardInsideOfGeoFenceRuleSucceeds()
        {
            var actionId = Guid.NewGuid().ToString("N");

            var realmRefId = Guid.NewGuid();

            var player = new Player()
            {
                RealmRefId = realmRefId,
            };

            player.Tags.Add("Fuu");

            var actions = new Actions()
            {
                new Common.Action()
                {
                    RealmRefId = realmRefId,
                    ReleasedOn = DateTimeOffset.UtcNow.AddSeconds(-60),
                    ActionId   = actionId,
                }
            };

            var sr = new List <SmartContext <ActionRequest> >()
            {
                new SmartContext <ActionRequest>()
                {
                    Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest()
                    {
                        ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddDays(-10)
                    }
                },
                new SmartContext <ActionRequest>()
                {
                    Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest()
                    {
                        ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-36)
                    }
                },
                new SmartContext <ActionRequest>()
                {
                    Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest()
                    {
                        ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-24)
                    }
                },
                new SmartContext <ActionRequest>()
                {
                    Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest()
                    {
                        ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-8)
                    }
                },
                new SmartContext <ActionRequest>()
                {
                    Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest()
                    {
                        ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddMinutes(-1)
                    }
                }
            };

            NetTopologySuite.Geometries.MultiPolygon insideOf = null;

            var jsonSerializer = NetTopologySuite.IO.GeoJsonSerializer.Create();

            using (StreamReader file = File.OpenText(@"GeorgiaGeoJsonData.json"))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    insideOf = jsonSerializer.Deserialize <NetTopologySuite.Geometries.MultiPolygon>(reader);
                }

            var coins = new Coins().LoadTestData(realmRefId);

            var awards = new Awards().LoadTestData(coins);

            var goal = new Goal().LoadTestData(realmRefId, awards);

            var goalTriggers = new GoalTriggers().LoadTestData(realmRefId, goal, actions, insideOf, null, null);;

            foreach (var goalTrigger in goalTriggers)
            {
                var events = new PlayerActionEvents();
                events.AddRange(
                    sr.Select(e =>
                              new PlayerActionEvent()
                {
                    OccurredAt = new NetTopologySuite.Geometries.Point(e.Longitude, e.Latitude)
                }.Map(e.Data, actions)
                              )
                    );

                var qualifyingActionRequests = goalTrigger.ValidateSteps(events);

                Assert.IsTrue(qualifyingActionRequests.Count > 0);
            }


            // the action is "read an ad"
            // step 1 read an ad on tuesday
            // step 2 read an ad on thursday



            // convert requests to Events
        }
 // Use this for initialization
 void Start()
 {
     events = transform.parent.gameObject.GetComponent<PlayerActionEvents>();
     events.lookDirectionChange += onMoveDirectionChange;
 }