Ejemplo n.º 1
0
    public int RemovePlayer(FantasyPlayer player)
    {
        int slotIndex = -1;

        if (SlotPlayer1.Name == player.Name)
        {
            SlotPlayer1.Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            slotIndex = 0;
        }
        else if (SlotPlayer2.Name == player.Name)
        {
            SlotPlayer2.Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            slotIndex = 1;
        }
        else if (SlotPlayer3.Name == player.Name)
        {
            SlotPlayer3.Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            slotIndex = 2;
        }
        else if (SlotPlayer4.Name == player.Name)
        {
            SlotPlayer4.Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            slotIndex = 3;
        }
        else
        {
            Logging.LogError("Unable to remove player from slot");
        }

        return(slotIndex);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Get a list of Fantasy Players from game sparks
    /// </summary>
    /// <returns>A list containing Fantasy Player objects for each player</returns>
    public static List <FantasyPlayer> GetFantasyPlayerList(System.Action callbackOnComplete)
    {
        List <FantasyPlayer> players = new List <FantasyPlayer>();

        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getFantasyTeams")
        .SetEventAttribute("team", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received FantasyPlayers from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data != null)
                    {
                        List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyPlayers");
                        if (dataList == null)
                        {
                            foreach (var obj in dataList)
                            {
                                // Populate a new fantasy team based on the info pulled from the dataList
                                string name          = obj.GetString("name");
                                FantasyPlayer player = new FantasyPlayer(null, null, null, null, null);

                                // @TODO: Continue populating team info

                                players.Add(player);
                            }
                        }
                        else
                        {
                            Logging.LogError("Couldn't get FantasyPlayers GSData");
                        }
                    }
                    else
                    {
                        Logging.LogError("FantasyPlayers ScriptData is NULL");
                    }
                }
                else
                {
                    Logging.LogError("FantasyPlayers response Base Data = null");
                }
            }
            else
            {
                Logging.Log("Error retrieving FantasyPlayers from GameSparks: " + response.Errors.ToString());
            }

            if (callbackOnComplete != null)
            {
                callbackOnComplete();
            }
        });

        return(players);
    }
Ejemplo n.º 3
0
    public int AddPlayer(FantasyPlayer player)
    {
        int slotIndex = -1;

        if (SlotPlayer1.Name == EMPTY)
        {
            SlotPlayer1.Configure(player);
            slotIndex = 0;
        }
        else if (SlotPlayer2.Name == EMPTY)
        {
            SlotPlayer2.Configure(player);
            slotIndex = 1;
        }
        else if (SlotPlayer3.Name == EMPTY)
        {
            SlotPlayer3.Configure(player);
            slotIndex = 2;
        }
        else if (SlotPlayer4.Name == EMPTY)
        {
            SlotPlayer4.Configure(player);
            slotIndex = 3;
        }
        else
        {
            Logging.LogError("Unable to add player to slot");
        }

        return(slotIndex);
    }
Ejemplo n.º 4
0
    public FantasyPlayer GetPlayerFromName(string name)
    {
        FantasyPlayer player = FantasyPlayersList.Find(fPlayer => fPlayer.Name.Equals(name));

        if (player != null)
        {
            return(player);
        }

        return(null);
    }
 public void Configure(FantasyPlayer player)
 {
     Configure(player.Name, player.Salary, player.Team, player.Points, player.Picture);
 }
Ejemplo n.º 6
0
    private void LoadFantasyPlayersFromGameSparks(System.Action cbOnComplete)
    {
        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getPlayers")
        .SetEventAttribute("team", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received Fantasy Players full list from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data == null)
                    {
                        Logging.LogError("ScriptData is NULL");
                        return;
                    }

                    List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyPlayers");
                    if (dataList == null)
                    {
                        Logging.LogError("Couldn't get FantasyPlayers GSData");
                        return;
                    }

                    foreach (var obj in dataList)
                    {
                        FantasyPlayer player = new FantasyPlayer();

                        player.Name   = obj.GetString("name");
                        player.Team   = obj.GetString("team");
                        player.Salary = obj.GetString("salary");
                        player.Points = obj.GetString("fppg");

                        System.Action <Texture2D> imageReceivedCB = delegate(Texture2D image)
                        {
                            Sprite playerImage = null;
                            if (image != null)
                            {
                                playerImage    = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f));
                                player.Picture = playerImage;
                            }
                        };

                        FantasyManager.Instance.DownloadAnImage(obj.GetString("portraitShortCode"), imageReceivedCB);

                        FantasyPlayersList.Add(player);
                    }

                    EventManager.instance.TriggerEvent(new EventFantasyPlayersListUpdated(System.DateTime.Now));
                }
                else
                {
                    Logging.LogError("response Base Data = null");
                }

                if (cbOnComplete != null)
                {
                    cbOnComplete.Invoke();
                }
            }
        });
    }
Ejemplo n.º 7
0
    public override void Initialize(object[] optionalParams)
    {
        base.Initialize(optionalParams);


        if (optionalParams == null)
        {
            Logging.LogError("Tried to initialize LineupView with optional params but the array was null!");
            return;
        }

        // Try to get a contest from the optional parameters (should never be null)
        contest = (ContestInfo)optionalParams[0];

        if (contest != null)
        {
            ContestName.text = contest.contestTitle;

            int i = 0;

            // Configure the player choices (on the lineup popup) based on the teams in the contest and hte players on those teams
            foreach (var team in contest.Teams)
            {
                foreach (var player in team.Players)
                {
                    FantasyPlayerChoices[i].gameObject.SetActive(true);

                    FantasyPlayerChoices[i].Configure(player);
                    player.OptionSlot = i;

                    FantasyPlayer fPlayer = player; // Avoid Boxing
                    FantasyPlayerChoices[i].AddButton.onClick.RemoveAllListeners();
                    FantasyPlayerChoices[i].AddButton.onClick.AddListener(() => AddFantasyPlayerToEntry(fPlayer));

                    FantasyPlayersSlot slot = FantasyPlayerChoices[i]; // Boxing
                    FantasyPlayerChoices[i].AddButton.onClick.AddListener(() => slot.gameObject.SetActive(false));

                    i++;
                }
            }

            // Turn off the remaining unused choices
            for (; i < FantasyPlayerChoices.Count; i++)
            {
                FantasyPlayerChoices[i].gameObject.SetActive(false);
            }


            for (int index = 0; index < FantasyPlayerChoices.Count; index++)
            {
                FantasyPlayerChoices[index].transform.SetSiblingIndex(index);
            }

            // Configure the current lineup slots with default parameters, including an empty name
            for (int j = 0; j < CurrentLineupSlots.Count; j++)
            {
                CurrentLineupSlots[j].Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            }

            CurrentContestEntry.SlotPlayer1.Name = EMPTY;
            CurrentContestEntry.SlotPlayer2.Name = EMPTY;
            CurrentContestEntry.SlotPlayer3.Name = EMPTY;
            CurrentContestEntry.SlotPlayer4.Name = EMPTY;
            CurrentContestEntry.SlotTeam1        = EMPTY;
            CurrentContestEntry.CurrentSalary    = 0;
            currentTotalFPPG = 0;
            fullSlots        = 0;

            RemainingSalaryText.text  = "$" + (baseSalary - CurrentContestEntry.CurrentSalary).ToString();
            AvgFantasyPointsText.text = "0.00";

            SubmitButton.interactable = false;
        }
    }
Ejemplo n.º 8
0
 public void RemoveFantasyPlayerFromEntry(FantasyPlayer player)
 {
     EventManager.instance.TriggerEvent(new EventContestEntryPlayerRemoved(player));
 }
Ejemplo n.º 9
0
 public void AddFantasyPlayerToEntry(FantasyPlayer player)
 {
     EventManager.instance.TriggerEvent(new EventContestEntryPlayerAdded(player));
 }
Ejemplo n.º 10
0
 public EventContestEntryPlayerRemoved(FantasyPlayer player)
 {
     removedPlayerId = player;
 }
 public EventContestEntryPlayerAdded(FantasyPlayer player)
 {
     addedPlayerId = player;
 }