Exemplo n.º 1
0
        public static void ShowPrivacyPolicy()
        {
            SpilLogging.Log("Opening Privacy Policy Screen");

            PrivacyPolicy = (GameObject)Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Spilgames/Editor/Prefabs/PrivacyPolicy.prefab"));
            PrivacyPolicy.SetActive(true);
        }
Exemplo n.º 2
0
        public static void ShowDailyBonus(JSONObject data, string url)
        {
            SpilLogging.Log("Opening URL: " + url + " With data: " + data.Print(false));

            SpilUnityImplementationBase.fireDailyBonusOpen();

            DailyBonus = (GameObject)Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Spilgames/Editor/Prefabs/DailyBonus.prefab"));
            DailyBonus.SetActive(true);
        }
Exemplo n.º 3
0
        public InventoryData InitInventory()
        {
            if (Inventory != null)
            {
                return(Inventory);
            }
            TempUserInfo temp;

            try {
                string playerData =
                    File.ReadAllText(Application.streamingAssetsPath + "/defaultPlayerData.json");
                temp = JsonHelper.getObjectFromJson <TempUserInfo>(playerData);
            }
            catch (FileNotFoundException e) {
                SpilLogging.Log("defaultPlayerData.json not found. Creating a placeholder! " + e);
                string placeholder =
                    "{\"wallet\":{\"currencies\":[],\"offset\": 0,\"logic\": \"CLIENT\"},\"inventory\":{\"items\":[],\"offset\":0,\"logic\": \"\"}}";
                temp = JsonHelper.getObjectFromJson <TempUserInfo>(placeholder);
            }

            // Currencies and items loaded from playerdata don't have fields like initialValue because those are defined in the gamedata. Add the missing information.
            // TODO: Should playerdata ever be used to access these fields or only gamedata? A. Check where these fields are being used (they shouldnt be? see SendUpdatePlayerDataEvent tho) and B. Consider maybe this is the wrong inheritance structure / we're exposing fields that shouldn't be exposed for playerdata items/currencies?
            // TODO: Make this prettier? Load both defaultPlayerData and defaultGameData.json and create/initialise wallet+inventory by combining data (instead of deserialising playerdata and adding missing data from gamedata afterwards)?
            if (temp != null && temp.inventory != null && temp.inventory.items != null)
            {
                if (SpilUnityEditorImplementation.gData == null)
                {
                    throw new NotImplementedException("GameData must be initialised before calling this method.");
                }

                foreach (PlayerItemData item in temp.inventory.items)
                {
                    SpilItemData gameDataItem = SpilUnityEditorImplementation.gData.items.FirstOrDefault(a => a.id == item.id);
                    if (gameDataItem != null)
                    {
                        item.content            = gameDataItem.content;
                        item.displayDescription = gameDataItem.displayDescription;
                        item.displayName        = gameDataItem.displayName;
                        item.imageUrl           = gameDataItem.imageUrl;
                        item.initialValue       = gameDataItem.initialValue;
                        item.isGacha            = gameDataItem.isGacha;
                        item.name = gameDataItem.name;
                        item.type = gameDataItem.type;
                    }
                    else
                    {
                        // TODO: Playerdata contains an item that is not defined in the gamedata, should this throw an exception?
                        // TODO: Remove the item from the list or keep it with missing data (as it is now)?
                    }
                }
            }

            return(temp.inventory);
        }
Exemplo n.º 4
0
        public void IAPPurchaseRequest()
        {
            if (Spil.IapPurchaseRequest == null || Spil.IapPurchaseRequest.Equals(""))
            {
                SpilLogging.Error("Iap Purchase Request SKU Id not set! Please configure value in the Spil SDK object!");
            }
            else
            {
                SpilUnityImplementationBase.fireIAPRequestPurchase(Spil.IapPurchaseRequest);
            }

            Destroy(SplashScreen);
        }
Exemplo n.º 5
0
        public static void ProcessRewardResponse(ResponseEvent response)
        {
            string reason = "";

            if (RewardManager.rewardFeatureType.ToString().ToLower().Trim().Equals(RewardManager.DeepLink))
            {
                reason = PlayerDataUpdateReasons.Deeplink;
            }
            else if (RewardManager.rewardFeatureType.ToString().ToLower().Trim().Equals(RewardManager.PushNotification))
            {
                reason = PlayerDataUpdateReasons.PushNotification;
            }

            if (RewardManager.rewardType == Spil.TokenRewardTypeEnum.EXTERNAL)
            {
                JSONObject rewards = new JSONObject(JSONObject.Type.ARRAY);

                JSONObject reward = new JSONObject();
                reward.AddField("externalId", Spil.TokenExternalRewardId);
                reward.AddField("amount", Spil.TokenRewardAmount);
                reward.AddField("type", RewardManager.rewardType.ToString());

                rewards.Add(reward);

                JSONObject json = new JSONObject();
                json.AddField("reward", rewards);
                json.AddField("rewardType", RewardManager.rewardFeatureType.ToString());

                SpilUnityImplementationBase.fireRewardTokenClaimed(json.Print());
            }
            else
            {
                int id     = Spil.TokenRewardId;
                int amount = Spil.TokenRewardAmount;

                if (id == 0 || amount == 0)
                {
                    SpilLogging.Error("Token Rewards not configured for Editor!");
                }

                if (RewardManager.rewardType == Spil.TokenRewardTypeEnum.CURRENCY)
                {
                    SpilUnityEditorImplementation.pData.WalletOperation("add", id, amount, reason, null, "DeepLink", null);
                }
                else if (RewardManager.rewardType == Spil.TokenRewardTypeEnum.ITEM)
                {
                    SpilUnityEditorImplementation.pData.InventoryOperation("add", id, amount, reason, null, "DeepLink", null);
                }
            }
        }
Exemplo n.º 6
0
    bool CheckAutomaticPermissionRequest()
    {
        string androidFolder   = "Assets/Plugins/Android/";
        string appManifestPath = androidFolder + "AndroidManifest.xml";

        // Let's open the app's AndroidManifest.xml file.
        XmlDocument manifestFile = new XmlDocument();

        manifestFile.Load(appManifestPath);

        XmlElement manifestRoot    = manifestFile.DocumentElement;
        XmlNode    applicationNode = null;

        foreach (XmlNode node in manifestRoot.ChildNodes)
        {
            if (node.Name == "application")
            {
                applicationNode = node;
                break;
            }
        }

        // If there's no applicatio node, something is really wrong with your AndroidManifest.xml.
        if (applicationNode == null)
        {
            SpilLogging.Error("Your app's AndroidManifest.xml file does not contain \"<application>\" node.");
            SpilLogging.Error("Unable to verify if the values were correct");

            return(true);
        }

        foreach (XmlNode node in applicationNode.ChildNodes)
        {
            if (node.Name.Equals("meta-data"))
            {
                if (node.Attributes["android:name"].Value.Equals("spil.permissions.DisableAutoRequest") &&
                    node.Attributes["android:value"].Value.Equals("true"))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
        public string GetGameData()
        {
            if (!updatedFromServer)
            {
                try {
                    string gameData = File.ReadAllText(Application.streamingAssetsPath + "/defaultGameData.json");
                    return(gameData);
                }
                catch (FileNotFoundException e) {
                    SpilLogging.Log("defaultGameData.json not found. Creating a placeholder!" + e.ToString());
                    string placeholder =
                        "{\"currencies\": [],\"promotions\": [],\"shop\": [],\"bundles\": [],\"items\": []}";
                    return(placeholder);
                }
            }

            return(JsonHelper.getJSONFromObject(this));
        }
        /// <summary>
        /// Sends an event to the native Spil SDK which will send a request to the back-end.
        /// Custom events may be tracked as follows:
        /// To track an simple custom event, simply call Spil.Instance.SendCustomEvent(String eventName); from anywhere in your code.
        /// To pass more information with the event create a &lt;String, String&gt; Dictionary and pass that as the second parameter like so:
        /// Dictionary&lt;String, String&gt; eventParams = new Dictionary&lt;String,String&gt;();
        /// eventParams.Add(“level”,levelName);
        /// Spil.Instance.SendCustomEvent(“PlayerDeath”, eventParams);
        /// See https://github.com/spilgames/spil_event_unity_plugin for more information on events.
        /// This method was previously called "TrackEvent".
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="dict"></param>
        public override void SendCustomEvent(string eventName, Dictionary <string, object> dict)
        {
            SpilLogging.Log("SpilSDK-Unity SendCustomEvent " + eventName);
            SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>();

            spilEvent.eventName = eventName;

            if (dict != null)
            {
                spilEvent.customData = JsonHelper.DictToJSONObject(dict);
                if (dict.ContainsKey("trackingOnly"))
                {
                    spilEvent.customData.RemoveField("trackingOnly");
                    spilEvent.customData.AddField("trackingOnly", true);
                    dict.Remove("trackingOnly");
                }
            }

            spilEvent.Send();
        }
Exemplo n.º 9
0
        public void CollectReward()
        {
            if (rewardType == Spil.DailyBonusRewardTypeEnum.EXTERNAL)
            {
                List <Reward> rewards = new List <Reward>();

                Reward reward = new Reward();
                reward.externalId = Spil.DailyBonusExternalId;
                reward.amount     = Spil.DailyBonusAmount;

                rewards.Add(reward);

                string rewardsJSON = JsonHelper.getJSONFromObject(rewards);

                JSONObject json = new JSONObject();
                json.AddField("data", rewardsJSON);

                SpilUnityImplementationBase.fireDailyBonusReward(json.Print(false));
            }
            else
            {
                int id     = Spil.DailyBonusId;
                int amount = Spil.DailyBonusAmount;

                if (id == 0 || amount == 0)
                {
                    SpilLogging.Error("Daily Bonus Rewards not configured for Editor!");
                }

                if (rewardType == Spil.DailyBonusRewardTypeEnum.CURRENCY)
                {
                    SpilUnityEditorImplementation.pData.WalletOperation("add", id, amount, PlayerDataUpdateReasons.DailyBonus, null, "DailyBonus", null);
                }
                else if (rewardType == Spil.DailyBonusRewardTypeEnum.ITEM)
                {
                    SpilUnityEditorImplementation.pData.InventoryOperation("add", id, amount, PlayerDataUpdateReasons.DailyBonus, null, "DailyBonus", null);
                }
            }

            Destroy(DailyBonus);
        }
Exemplo n.º 10
0
    public static string GetData(string type)
    {
        string  data = "";
        WWWForm form = GetFormData();

        form.AddField("name", type);
        WWW request = new WWW("https://apptracker.spilgames.com/v1/native-events/event/android/" + bundleIdentifier + "/" + type, form);

        while (!request.isDone)
        {
            ;
        }
        if (request.error != null && !request.error.Equals(""))
        {
            SpilLogging.Error("Error getting game data: " + request.error);
        }
        else
        {
            JSONObject serverResponse = new JSONObject(request.text);
            data = serverResponse.GetField("data").ToString();
        }
        return(data);
    }
        public static void ProcessAdvanceToNextStage(JSONObject response)
        {
            bool valid = response.GetField("valid").b;

            if (!valid)
            {
                SpilLogging.Error("Error validating live event next stage!");
                CloseStageView();
                return;
            }

            liveEventOverview.currentStage = null;
            if (response.HasField("nextStage"))
            {
                liveEventOverview.currentStage = response.GetField("nextStage");

                JSONObject rewards = new JSONObject(JSONObject.Type.ARRAY);
                rewards.Add(liveEventOverview.currentStage.GetField("rewards"));
                liveEventOverview.currentStage.AddField("rewards", rewards);
            }
            else if (response.HasField("noMoreStages"))
            {
                SpilUnityImplementationBase.fireLiveEventCompleted();
                CloseStageView();
                return;
            }

            if (liveEventOverview.currentStage != null)
            {
                OpenStageView(StageType.PROGRESS, liveEventOverview.currentStage);
            }
            else
            {
                SpilLogging.Error("Error opening next stage due to missing data!");
            }
        }
        public static void ProcessApplyItems(JSONObject response)
        {
            bool valid = response.GetField("valid").b;

            if (!valid)
            {
                SpilLogging.Error("Error validating live event next stage!");
                CloseStageView();
                return;
            }

            bool metRequirements = response.GetField("metRequirements").b;

            if (!metRequirements)
            {
                SpilUnityImplementationBase.fireLiveEventMetRequirements(false);
                if (response.HasField("progress"))
                {
                    liveEventOverview.currentStage.RemoveField("progress");
                    liveEventOverview.currentStage.AddField("progress", response.GetField("progress"));
                }
                CloseStageView();
                return;
            }
            SpilUnityImplementationBase.fireLiveEventMetRequirements(true);

            if (rewardType == Spil.LiveEventRewardTypeEnum.EXTERNAL)
            {
                List <Reward> rewards = new List <Reward>();

                Reward reward = new Reward();
                reward.externalId = Spil.LiveEventExternalRewardId;
                reward.amount     = Spil.LiveEventRewardAmount;

                rewards.Add(reward);

                string rewardsJSON = JsonHelper.getJSONFromObject(rewards);

                JSONObject json = new JSONObject();
                json.AddField("data", rewardsJSON);

                SpilUnityImplementationBase.fireLiveEventReward(json.Print());
            }
            else
            {
                int id     = Spil.LiveEventRewardId;
                int amount = Spil.LiveEventRewardAmount;

                if (id == 0 || amount == 0)
                {
                    SpilLogging.Error("Daily Bonus Rewards not configured for Editor!");
                }

                if (rewardType == Spil.LiveEventRewardTypeEnum.CURRENCY)
                {
                    SpilUnityEditorImplementation.pData.WalletOperation("add", id, amount, PlayerDataUpdateReasons.LiveEvent, null, "LiveEvent", null);
                }
                else if (rewardType == Spil.LiveEventRewardTypeEnum.ITEM)
                {
                    SpilUnityEditorImplementation.pData.InventoryOperation("add", id, amount, PlayerDataUpdateReasons.LiveEvent, null, "LiveEvent", null);
                }
            }

            JSONObject nextStage = response.GetField("nextStage");

            nextStage.AddField("givenReward", response.GetField("reward"));

            JSONObject nextStageRewards = new JSONObject(JSONObject.Type.ARRAY);

            nextStageRewards.Add(liveEventOverview.currentStage.GetField("rewards"));
            liveEventOverview.currentStage.AddField("rewards", nextStageRewards);

            liveEventOverview.currentStage = nextStage;
            OpenStageView(StageType.INFO, nextStage);
        }
        public static void ProcessRequestLiveEvent(JSONObject response)
        {
            if (response != null && response.Count > 0)
            {
                if (response.HasField("config"))
                {
                    liveEventOverview.liveEventConfig = response.GetField("config");
                }

                if (response.HasField("currentStage"))
                {
                    liveEventOverview.currentStage = response.GetField("currentStage");

                    JSONObject rewards = new JSONObject(JSONObject.Type.ARRAY);
                    rewards.Add(liveEventOverview.currentStage.GetField("rewards"));
                    liveEventOverview.currentStage.AddField("rewards", rewards);
                }

                if (response.HasField("alwaysShowStartStage"))
                {
                    liveEventOverview.alwaysShowStartStage = response.GetField("alwaysShowStartStage").b;
                }

                if (response.HasField("eventItems"))
                {
                    liveEventOverview.eventItems = response.GetField("eventItems");
                }

                if (response.HasField("liveEventId"))
                {
                    liveEventOverview.liveEventId = (int)response.GetField("liveEventId").n;
                }

                if (response.HasField("startDate"))
                {
                    liveEventOverview.startDate = (long)response.GetField("startDate").n;
                }

                if (response.HasField("endDate"))
                {
                    liveEventOverview.endDate = (long)response.GetField("endDate").n;
                }

                if (response.HasField("stage"))
                {
                    JSONObject startStage = response.GetField("stage");

                    JSONObject rewards = new JSONObject(JSONObject.Type.ARRAY);
                    rewards.Add(startStage.GetField("rewards"));

                    startStage.AddField("rewards", rewards);

                    liveEventOverview.startStage = startStage;

                    SpilUnityImplementationBase.fireLiveEventAvailable();
                }
            }
            else
            {
                SpilLogging.Error("Error retrieving live event data!");
            }
        }
 public void SetStagingEnvironment()
 {
     SpilLogging.Log("Set environment: staging!");
 }
Exemplo n.º 15
0
    void VerifyAndroidSetup()
    {
        bool isEverythingCorrect = true;

        string androidFolder = "Assets/Plugins/Android/";

        if (Directory.Exists(androidFolder + "GooglePlayServices"))
        {
            SpilLogging.Error(
                "The contents of the GooglePlayServices folder should be copied into 'Assets/Plugins/Android/' and afterwards the folder should be removed");
            isEverythingCorrect = false;
        }

        string appManifestPath = androidFolder + "AndroidManifest.xml";

        // Let's open the app's AndroidManifest.xml file.
        XmlDocument manifestFile = new XmlDocument();

        manifestFile.Load(appManifestPath);

        XmlElement manifestRoot    = manifestFile.DocumentElement;
        XmlNode    applicationNode = null;

        foreach (XmlNode node in manifestRoot.ChildNodes)
        {
            if (node.Name == "application")
            {
                applicationNode = node;
                break;
            }
        }

        // If there's no applicatio node, something is really wrong with your AndroidManifest.xml.
        if (applicationNode == null)
        {
            SpilLogging.Error("Your app's AndroidManifest.xml file does not contain \"<application>\" node.");
            SpilLogging.Error("Unable to verify if the values were correct");

            return;
        }

        if (!applicationNode.Attributes["android:name"].Value.Equals("com.spilgames.spilsdk.activities.SpilSDKApplication"))
        {
            SpilLogging.Error("The application name from your \"AndroidManifest.xml\" file is set incorrectly. Please set it to either \"com.spilgames.spilsdk.activities.SpilSDKApplication\" if you want for the Spil SDK to function correctly");
            isEverythingCorrect = false;
        }

        if (applicationNode.Attributes["android:name"].Value.Equals("com.spilgames.spilsdk.activities.SpilSDKApplicationWithFabric"))
        {
            SpilLogging.Error("The application name found in your \"AndroidManifest.xml\" file is set incorrectly. The application name \"com.spilgames.spilsdk.activities.SpilSDKApplicationWithFabric\" has been removed from the Spil SDK. Please use the standard \"com.spilgames.spilsdk.activities.SpilSDKApplication\". The Fabric (Crashlytics functionality has been moved to this application name.");
            isEverythingCorrect = false;
        }

        bool isUnityRequestPermissionDisabled = false;

        foreach (XmlNode node in applicationNode.ChildNodes)
        {
            if (node.Name.Equals("activity"))
            {
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    if (subNode.Name.Equals("intent-filter"))
                    {
                        foreach (XmlNode bottomNode in subNode.ChildNodes)
                        {
                            if (bottomNode.Name.Equals("action") && bottomNode.Attributes["android:name"].Value
                                .Equals("android.intent.action.MAIN"))
                            {
                                if (!(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivity")) &&
                                    !(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivityWithPrime")) &&
                                    !(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivityWithAN")))
                                {
                                    SpilLogging.Error(
                                        "The Main Activity name from your \"AndroidManifest.xml\" file is set incorrectly. Please set it to either \"com.spilgames.spilsdk.activities.SpilUnityActivity\", \"com.spilgames.spilsdk.activities.SpilUnityActivityWithPrime\" (if you are using Prime31 Plugin) or \"com.spilgames.spilsdk.activities.SpilUnityActivityWithAN\" (if you are using Android Native Plugin) if you want for the Spil SDK to function correctly");
                                    isEverythingCorrect = false;
                                }
                            }
                        }
                    }
                }
            }

            if (node.Name.Equals("meta-data"))
            {
                if (node.Attributes["android:name"].Value.Equals("unityplayer.SkipPermissionsDialog") &&
                    node.Attributes["android:value"].Value.Equals("true"))
                {
                    isUnityRequestPermissionDisabled = true;
                    isEverythingCorrect = false;
                }
            }
        }

        if (!isUnityRequestPermissionDisabled)
        {
            SpilLogging.Error(
                "You did not disable the automatic Unity permission request. Please add the following line to your \"applicaiton\" tag: \"<meta-data android:name=\"unityplayer.SkipPermissionsDialog\" android:value=\"true\" />\". This is required in order to not have any problems with the Spil SDK's permission system. Keep in mind that all your dangerous permissions will be handled by the Spil SDK automatically");
        }

        if (!isEverythingCorrect)
        {
            SpilLogging.Log("Verification Complete! The Spil SDK for Android is configured correctly!");
        }
        else
        {
            SpilLogging.Error("Verification Complete! Something was not configured correctly!! Please check the logs");
        }
    }
        public static void ProcessAdvertisementResponse(ResponseEvent response)
        {
            if (response.action.Equals("init"))
            {
                JSONObject provider = response.data.GetField("providers");

                if (provider.HasField("DFP"))
                {
                    AdvertisementManager.DFPEnabled = true;
                    SpilLogging.Log("DFP Enabled");
                }

                if (provider.HasField("Fyber"))
                {
                    AdvertisementManager.FyberEnabled = true;
                    SpilLogging.Log("Fyber Enabled");
                }

                if (provider.HasField("Chartboost") || provider.HasField("ChartBoost"))
                {
                    AdvertisementManager.ChartboostEnabled = true;
                    SpilLogging.Log("Chartboost Enabled");
                }
            }
            else if (response.action.Equals("show"))
            {
                int priv = Spil.Instance.GetPrivValue();

                if (priv < 2 && priv > -1)
                {
                    return;
                }

                string provider = response.data.GetField("provider").str;
                string adType   = response.data.GetField("adType").str;

                int  probability = Random.Range(0, 100);
                bool available   = probability > 20;

                if (provider.ToLower().Trim().Equals("dfp"))
                {
                    if (available)
                    {
                        SpilLogging.Log("DFP Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                        AdvertisementManager.PlayInterstitial("DFP");
                    }
                    else
                    {
                        SpilLogging.Log("DFP Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
                else if (provider.ToLower().Trim().Equals("fyber"))
                {
                    if (available)
                    {
                        SpilLogging.Log("Fyber Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                    }
                    else
                    {
                        SpilLogging.Log("Fyber Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
                else if (provider.ToLower().Trim().Equals("chartboost"))
                {
                    if (available)
                    {
                        SpilLogging.Log("Chartboost Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                        AdvertisementManager.PlayInterstitial("Chartboost");
                    }
                    else
                    {
                        SpilLogging.Log("Chartboost Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void OpenGacha(int gachaId, string reason, string reasonDetails, string location)
        {
            PlayerItemData gachaPlayerItem = GetGachaFromInventory(gachaId);
            SpilItemData   gachaItem       = GetGachaFromObjects(gachaId);

            if (gachaPlayerItem == null || gachaItem == null || gachaId <= 0 || reason == null || !gachaPlayerItem.isGacha)
            {
                SpilLogging.Error("Error opening gacha!");
                return;
            }

            if (!gachaPlayerItem.content.All(gachaItem.content.Contains) && gachaPlayerItem.content.Count == gachaItem.content.Count)
            {
                gachaPlayerItem.content = gachaItem.content;
            }

            if (gachaPlayerItem.amount < 1)
            {
                SpilLogging.Error("Not enough gacha boxes in the inventory!");
                return;
            }

            if (gachaPlayerItem.content.Count < 1)
            {
                SpilLogging.Error("Error opening gacha! No content present!");
                return;
            }

            int weightSum = 0;

            foreach (SpilGachaContent gachaContent in gachaPlayerItem.content)
            {
                weightSum = weightSum + gachaContent.weight;
            }

            if (weightSum == 0)
            {
                SpilLogging.Error("Error opening gacha!");
                return;
            }

            int rand = Random.Range(0, weightSum);

            int low  = 0;
            int high = 0;

            for (int i = 0; i < gachaPlayerItem.content.Count; i++)
            {
                SpilGachaContent gachaContent = gachaPlayerItem.content[i];

                if (i != 0)
                {
                    low = high;
                }

                high = low + gachaContent.weight;

                if (rand >= low && rand < high)
                {
                    gachaPlayerItem.amount = gachaPlayerItem.amount - 1;
                    gachaPlayerItem.delta  = gachaPlayerItem.delta - 1;

                    UpdateItem(gachaPlayerItem);

                    switch (gachaContent.type)
                    {
                    case "CURRENCY":
                        WalletOperation("add", gachaContent.id, gachaContent.amount, reason, reasonDetails, location, null);
                        break;

                    case "ITEM":
                        InventoryOperation("add", gachaContent.id, gachaContent.amount, reason, reasonDetails, location, null);
                        break;

                    case "BUNDLE":
                        OpenBundle(gachaContent.id, gachaContent.amount, reason, reasonDetails, location);
                        break;

                    case "GACHA":
                        InventoryOperation("add", gachaContent.id, gachaContent.amount, reason, reasonDetails, location, null);
                        break;

                    case "NONE":
                        UserDataManager.UpdateUserDataVersions();
                        UserDataManager.UpdateUserDataMeta();

                        PlayerDataUpdatedData updatedData = new PlayerDataUpdatedData();
                        updatedData.items.Add(gachaPlayerItem);
                        updatedData.reason = reason;

                        SpilUnityImplementationBase.firePlayerDataEmptyGacha();
                        SpilUnityImplementationBase.firePlayerDataUpdated(JsonHelper.getJSONFromObject(updatedData));
                        break;

                    default:
                        SpilLogging.Error("Error opening gacha!");
                        return;
                    }

                    break;
                }
            }
        }
Exemplo n.º 18
0
        public void BuyBundle(int bundleId, string reason, string reasonDetails, string location, string transactionId)
        {
            PlayerDataUpdatedData updatedData = new PlayerDataUpdatedData();

            SpilBundleData bundle = GetBundleFromObjects(bundleId);

            if (bundle == null || reason == null)
            {
                SpilLogging.Error("Error adding bundle to player inventory!");
                return;
            }

            Promotion promotion        = Spil.Instance.GetPromotions().GetBundlePromotion(bundleId);
            bool      isPromotionValid = false;

            if (promotion != null)
            {
                isPromotionValid = promotion.IsValid();
            }

            List <SpilBundlePriceData> bundlePrices = new List <SpilBundlePriceData>();

            if (isPromotionValid)
            {
                foreach (PriceOverride priceOverride in promotion.PriceOverride)
                {
                    SpilBundlePriceData bundlePriceData = new SpilBundlePriceData();
                    bundlePriceData.currencyId = priceOverride.Id;
                    bundlePriceData.value      = priceOverride.Amount;

                    bundlePrices.Add(bundlePriceData);
                }
            }
            else
            {
                bundlePrices = bundle.prices;
            }

            foreach (SpilBundlePriceData bundlePrice in bundlePrices)
            {
                PlayerCurrencyData currency = GetCurrencyFromWallet(bundlePrice.currencyId);

                if (currency == null)
                {
                    SpilLogging.Error("Currency does not exist!");
                    return;
                }

                int currentBalance = currency.currentBalance;
                int updatedBalance = currentBalance - bundlePrice.value;

                if (updatedBalance < 0)
                {
                    SpilLogging.Error("Not enough balance for currency!");
                    return;
                }

                int updatedDelta = -bundlePrice.value + currency.delta;

                if (updatedDelta == 0)
                {
                    updatedDelta = -bundlePrice.value;
                }

                currency.delta          = updatedDelta;
                currency.currentBalance = updatedBalance;

                UpdateCurrency(currency);
                updatedData.currencies.Add(currency);
            }

            foreach (SpilBundleItemData bundleItem in bundle.items)
            {
                SpilItemData gameItem = GetItemFromObjects(bundleItem.id);

                if (gameItem == null)
                {
                    SpilLogging.Error("Item does not exist!");
                    return;
                }
                ;
                PlayerItemData item = new PlayerItemData();
                item.id                 = gameItem.id;
                item.name               = gameItem.name;
                item.type               = gameItem.type;
                item.displayName        = gameItem.displayName;
                item.displayDescription = gameItem.displayDescription;
                item.isGacha            = gameItem.isGacha;
                item.content            = gameItem.content;

                PlayerItemData inventoryItem = GetItemFromInventory(bundleItem.id);

                int inventoryItemAmount;

                if (inventoryItem != null)
                {
                    inventoryItemAmount = inventoryItem.amount;

                    inventoryItemAmount = inventoryItemAmount + bundleItem.amount;

                    inventoryItem.delta  = bundleItem.amount;
                    inventoryItem.amount = inventoryItemAmount;

                    UpdateItem(inventoryItem);

                    updatedData.items.Add(inventoryItem);
                }
                else
                {
                    inventoryItemAmount = bundleItem.amount;

                    item.delta  = inventoryItemAmount;
                    item.amount = inventoryItemAmount;

                    Inventory.items.Add(item);

                    updatedData.items.Add(item);
                }
            }

            if (isPromotionValid)
            {
                foreach (ExtraEntity extraEntity in promotion.ExtraEntities)
                {
                    if (extraEntity.Type.Equals("CURRENCY"))
                    {
                        PlayerCurrencyData currency = GetCurrencyFromWallet(extraEntity.Id);

                        if (currency == null)
                        {
                            SpilLogging.Error("Currency does not exist!");
                            return;
                        }

                        currency.currentBalance = currency.currentBalance + extraEntity.Amount;
                        currency.delta          = currency.delta + extraEntity.Amount;

                        UpdateCurrency(currency);

                        PlayerCurrencyData temp = null;

                        foreach (PlayerCurrencyData playerCurrency in updatedData.currencies)
                        {
                            if (playerCurrency.id == extraEntity.Id)
                            {
                                temp = playerCurrency;
                            }
                        }

                        if (temp != null)
                        {
                            updatedData.currencies.Remove(temp);
                        }

                        updatedData.currencies.Add(currency);
                    }
                    else if (extraEntity.Type.Equals("ITEM") || extraEntity.Type.Equals("GACHA"))
                    {
                        SpilItemData gameItem = GetItemFromObjects(extraEntity.Id);

                        if (gameItem == null)
                        {
                            SpilLogging.Error("Item does not exist!");
                            return;
                        }
                        ;
                        PlayerItemData item = new PlayerItemData();
                        item.id                 = gameItem.id;
                        item.name               = gameItem.name;
                        item.type               = gameItem.type;
                        item.displayName        = gameItem.displayName;
                        item.displayDescription = gameItem.displayDescription;
                        item.isGacha            = gameItem.isGacha;
                        item.content            = gameItem.content;

                        PlayerItemData inventoryItem = GetItemFromInventory(extraEntity.Id);

                        int inventoryItemAmount;

                        if (inventoryItem != null)
                        {
                            inventoryItemAmount = inventoryItem.amount;

                            inventoryItemAmount = inventoryItemAmount + extraEntity.Amount;

                            inventoryItem.delta  = extraEntity.Amount;
                            inventoryItem.amount = inventoryItemAmount;

                            UpdateItem(inventoryItem);

                            PlayerItemData temp = null;

                            foreach (PlayerItemData playerItem in updatedData.items)
                            {
                                if (playerItem.id == extraEntity.Id)
                                {
                                    temp = playerItem;
                                }
                            }

                            if (temp != null)
                            {
                                updatedData.items.Remove(temp);
                            }

                            updatedData.items.Add(inventoryItem);
                        }
                        else
                        {
                            inventoryItemAmount = extraEntity.Amount;

                            item.delta  = inventoryItemAmount;
                            item.amount = inventoryItemAmount;

                            Inventory.items.Add(item);

                            updatedData.items.Add(item);
                        }
                    }
                }
            }

            UserDataManager.UpdateUserDataVersions();
            UserDataManager.UpdateUserDataMeta();

            updatedData.reason = reason;

            SpilUnityImplementationBase.firePlayerDataUpdated(JsonHelper.getJSONFromObject(updatedData));

            if (isPromotionValid)
            {
                PromotionsManager.PromotionData.First(a => a.id == promotion.Id).amountPurchased++;

                PromotionsManager.SendBoughtPromotion(promotion.Id);
            }

            SendUpdatePlayerDataEvent(bundle, reason, reasonDetails, location, transactionId);
        }
Exemplo n.º 19
0
        public void InventoryOperation(string action, int itemId, int amount, string reason, string reasonDetails, string location, string transactionId)
        {
            SpilItemData gameItem = GetItemFromObjects(itemId);

            if (gameItem == null || itemId <= 0 || action == null || reason == null)
            {
                SpilLogging.Error("Error updating item to player inventory!");
                return;
            }

            PlayerItemData item = new PlayerItemData();

            item.id                 = gameItem.id;
            item.name               = gameItem.name;
            item.type               = gameItem.type;
            item.displayName        = gameItem.displayName;
            item.displayDescription = gameItem.displayDescription;
            item.isGacha            = gameItem.isGacha;
            item.content            = gameItem.content;
            item.amount             = amount;
            item.delta              = amount;

            PlayerItemData inventoryItem = GetItemFromInventory(itemId);

            if (inventoryItem != null)
            {
                int inventoryItemAmount = inventoryItem.amount;

                if (action.Equals("add"))
                {
                    inventoryItemAmount = inventoryItemAmount + amount;
                }
                else if (action.Equals("subtract"))
                {
                    inventoryItemAmount = inventoryItemAmount - amount;

                    if (inventoryItemAmount < 0)
                    {
                        SpilLogging.Error("Could not remove item as amount is too low!");
                        return;
                    }
                }

                inventoryItem.delta  = amount;
                inventoryItem.amount = inventoryItemAmount;
                UpdateItem(inventoryItem);
            }
            else
            {
                if (action.Equals("add"))
                {
                    Inventory.items.Add(item);
                }
                else if (action.Equals("subtract"))
                {
                    SpilLogging.Error("Could not remove item as amount is too low!");
                }
            }

            UserDataManager.UpdateUserDataVersions();
            UserDataManager.UpdateUserDataMeta();

            PlayerDataUpdatedData updatedData = new PlayerDataUpdatedData();

            updatedData.items.Add(item);
            updatedData.reason = reason;

            SpilUnityImplementationBase.firePlayerDataUpdated(JsonHelper.getJSONFromObject(updatedData));

            SendUpdatePlayerDataEvent(null, reason, reasonDetails, location, transactionId);
        }
Exemplo n.º 20
0
        public void WalletOperation(string action, int currencyId, int amount, string reason, string reasonDetails, string location, string transactionId)
        {
            if (currencyId <= 0 || reason == null)
            {
                SpilLogging.Error("Error updating wallet!");
                return;
            }

            PlayerCurrencyData currency = null;

            foreach (PlayerCurrencyData playerCurrency in Wallet.currencies)
            {
                if (playerCurrency.id == currencyId)
                {
                    currency = playerCurrency;
                }
            }

            if (currency == null)
            {
                SpilLogging.Error("Currency does not exist!");
                return;
            }

            int currentBalance = currency.currentBalance;

            if (action.Equals("subtract"))
            {
                amount = -amount;
            }

            int updatedBalance = currentBalance + amount;

            if (updatedBalance < 0)
            {
                SpilLogging.Error("Not enough balance for currency!");
                return;
            }

            int updatedDelta = amount + currency.delta;

            if (updatedDelta == 0)
            {
                updatedDelta = amount;
            }

            currency.delta          = updatedDelta;
            currency.currentBalance = updatedBalance;

            if (Wallet.logic.Equals("CLIENT"))
            {
                UpdateCurrency(currency);

                UserDataManager.UpdateUserDataVersions();
                UserDataManager.UpdateUserDataMeta();

                PlayerDataUpdatedData updatedData = new PlayerDataUpdatedData();
                updatedData.currencies.Add(currency);
                updatedData.reason = reason;

                SpilUnityImplementationBase.firePlayerDataUpdated(JsonHelper.getJSONFromObject(updatedData));

                SendUpdatePlayerDataEvent(null, reason, reasonDetails, location, transactionId);
            }
            else if (Wallet.logic.Equals("SERVER"))
            {
            }
        }
Exemplo n.º 21
0
    void CreateDefaultConfigFiles()
    {
        if (androidPackageName == "" || iosBundelId == "")
        {
            throw new UnityException("Bundle ID is Blank");
        }
        SpilLogging.Log("Getting Default Files for Android: " + androidPackageName + ", And iOS: " + iosBundelId);
        string streamingAssetsPath = Application.dataPath + "/StreamingAssets";

        if (!File.Exists(streamingAssetsPath))
        {
            Directory.CreateDirectory(streamingAssetsPath);
        }
        if (!File.Exists(streamingAssetsPath + "/defaultGameData.json"))
        {
            File.WriteAllText(streamingAssetsPath + "/defaultGameData.json", GetData("requestGameData"));
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultGameData.json");
            File.WriteAllText(streamingAssetsPath + "/defaultGameData.json", GetData("requestGameData"));
        }

        if (!File.Exists(streamingAssetsPath + "/defaultGameConfig.json"))
        {
            string configResponse = GetData("requestConfig");
            File.WriteAllText(streamingAssetsPath + "/defaultGameConfig.json", configResponse);
            configJSON = new JSONObject(configResponse);

            android = null;
            ios     = null;
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultGameConfig.json");
            string configResponse = GetData("requestConfig");
            File.WriteAllText(streamingAssetsPath + "/defaultGameConfig.json", configResponse);
            configJSON = new JSONObject(configResponse);

            android = null;
            ios     = null;
        }

        if (!File.Exists(streamingAssetsPath + "/defaultPlayerData.json"))
        {
            JSONObject gameData   = new JSONObject(GetData("requestGameData"));
            JSONObject playerData = new JSONObject(GetData("requestPlayerData"));

            for (int i = 0; i < gameData.GetField("currencies").Count; i++)
            {
                JSONObject currency = new JSONObject();
                currency.AddField("id", gameData.GetField("currencies").list[i].GetField("id"));
                currency.AddField("currentBalance", 0);
                currency.AddField("delta", 0);

                playerData.GetField("wallet").GetField("currencies").Add(currency);
            }

            playerData.GetField("wallet").RemoveField("offset");
            playerData.GetField("wallet").AddField("offset", 0);

            playerData.GetField("inventory").RemoveField("offset");
            playerData.GetField("inventory").AddField("offset", 0);

            File.WriteAllText(streamingAssetsPath + "/defaultPlayerData.json", playerData.Print(false));
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultPlayerData.json");

            JSONObject gameData   = new JSONObject(GetData("requestGameData"));
            JSONObject playerData = new JSONObject(GetData("requestPlayerData"));

            for (int i = 0; i < gameData.GetField("currencies").Count; i++)
            {
                JSONObject currency = new JSONObject();
                currency.AddField("id", gameData.GetField("currencies").list[i].GetField("id"));
                currency.AddField("currentBalance", 0);
                currency.AddField("delta", 0);

                playerData.GetField("wallet").GetField("currencies").Add(currency);
            }

            playerData.GetField("wallet").RemoveField("offset");
            playerData.GetField("wallet").AddField("offset", 0);

            playerData.GetField("inventory").RemoveField("offset");
            playerData.GetField("inventory").AddField("offset", 0);

            File.WriteAllText(streamingAssetsPath + "/defaultPlayerData.json", playerData.Print(false));
        }

        if (retrievalError)
        {
            SpilLogging.Error("Error retrieving default files! Please check the logs!");
        }
        else
        {
            SpilLogging.Log("Default files succesfully retrieved!");
        }
        retrievalError = false;
    }
Exemplo n.º 22
0
    string GetData(string type)
    {
        string gameData = "";

        if (type.Equals("requestConfig"))
        {
            JSONObject combined = new JSONObject();

            WWWForm form = GetFormData("android");
            form.AddField("name", type);
            WWW request =
                new WWW(
                    "https://apptracker.spilgames.com/v1/native-events/event/android/" + androidPackageName + "/" +
                    type,
                    form);
            while (!request.isDone)
            {
                ;
            }
            if (request.error != null && !request.error.Equals(""))
            {
                SpilLogging.Error("Error getting game data: " + request.error + ". Request: " + request.url +
                                  ". App version: " + androidGameVersion);
                combined.AddField("androidSdkConfig", "");
                retrievalError = true;
            }
            else
            {
                combined = new JSONObject(request.text).GetField("data");
            }

            WWWForm form2 = GetFormData("ios");
            form2.AddField("name", type);
            WWW request2 =
                new WWW("https://apptracker.spilgames.com/v1/native-events/event/ios/" + iosBundelId + "/" + type,
                        form2);
            while (!request2.isDone)
            {
                ;
            }
            if (request2.error != null && !request2.error.Equals(""))
            {
                SpilLogging.Error("Error getting game data: " + request2.error + ". Request: " + request2.url +
                                  ". App version: " + iosGameVersion);
                combined.AddField("iosSdkConfig", "");
                retrievalError = true;
            }
            else
            {
                if (combined.HasField("iosSdkConfig"))
                {
                    combined.RemoveField("iosSdkConfig");
                }
                combined.AddField("iosSdkConfig",
                                  new JSONObject(request2.text).GetField("data").GetField("iosSdkConfig"));
            }
            gameData = combined.Print(false);
        }
        else
        {
            WWWForm form = GetFormData(EditorUserBuildSettings.activeBuildTarget.ToString().Trim().ToLower());
            form.AddField("name", type);

            string bundleIdentifier = null;
#if UNITY_ANDROID
            bundleIdentifier = androidPackageName;
#elif UNITY_IPHONE || UNITY_TVOS
            bundleIdentifier = iosBundelId;
#endif

            WWW request =
                new WWW(
                    "https://apptracker.spilgames.com/v1/native-events/event/" +
                    EditorUserBuildSettings.activeBuildTarget.ToString().Trim().ToLower() + "/" + bundleIdentifier +
                    "/" + type, form);
            while (!request.isDone)
            {
                ;
            }
            if (request.error != null && !request.error.Equals(""))
            {
                SpilLogging.Error("Error getting data: " + request.error + " " + request.text);
                retrievalError = true;
            }
            else
            {
                JSONObject serverResponce = new JSONObject(request.text);
                gameData = serverResponce.GetField("data").ToString();
            }
        }


        return(gameData);
    }
 public void RequestDangerousPermission(string permission, string rationale)
 {
     SpilLogging.Log("Requested permission: " + permission);
 }
 public static void ProcessDroppedResponse(string message)
 {
     SpilLogging.Log("Update event dropped. Message: " + message);
 }
 public void SetProductionEnvironment()
 {
     SpilLogging.Log("Set environment: production!");
 }