Beispiel #1
0
        /// <summary>
        /// Saves a friend as hired for the provided job and then returns that friend's avatar's DNA to the client
        /// </summary>
        /// <param name="message"></param>
        private void HireFriend(Message message, Guid sessionId)
        {
            mLogger.Debug("HireFriend: " + message.ToString());
            if (message.Data.Count != 3)
            {
                mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 4, actual was " + message.Data.Count);
                return;
            }

            long facebookId;

            if (!long.TryParse(message.Data[1].ToString(), out facebookId))
            {
                mLogger.Error("Dropping Message (" + message + "), expected Data[1] to be able to parse to long. Value: " + message.Data[1]);
                return;
            }

            Jobs          job           = (Jobs)Enum.Parse(typeof(Jobs), message.Data[2].ToString());
            string        jobName       = job.ToString();
            ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);

            FashionMinigameServiceAPI.GetGameData(serverAccount, jobName, delegate(XmlDocument resultXml)
            {
                XmlNode hiredFriendsListNode = resultXml.SelectSingleNode
                                               (
                    "//DataKey[@KeyName='" + jobName + "']"
                                               );

                string dataValue;
                if (hiredFriendsListNode == null)
                {
                    dataValue = facebookId.ToString();
                }
                else
                {
                    dataValue = String.Format("{0},{1}", hiredFriendsListNode.InnerText, facebookId.ToString());
                }
                FashionMinigameServiceAPI.SetGameData(serverAccount, jobName, dataValue, delegate(XmlDocument responseXml)
                {
                    VerifySuccess(responseXml);

                    Action <List <object> > returnHiredFriend = delegate(List <object> responseData)
                    {
                        Message responseMessage = new Message();
                        responseData.Insert(0, message.Data[0]);                         // callback Id
                        responseData.Insert(1, jobName);
                        responseMessage.FashionGameHireFriend(responseData);
                        SendMessageToClient(responseMessage, sessionId);
                    };

                    ProcessHiredFriends(serverAccount, returnHiredFriend, new List <object>(), new long[] { facebookId });
                });
            });
        }
Beispiel #2
0
        private void SetPlayerGameData(Message message, Guid sessionId)
        {
            mLogger.Debug("SetPlayerGameData: " + message.ToString());
            if (message.Data.Count < 2)
            {
                mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 3, actual was " + message.Data.Count);
                return;
            }

            string dataKey   = CheckType.TryAssignType <string>(message.Data[0]);
            string dataValue = CheckType.TryAssignType <string>(message.Data[1]);

            ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);

            FashionMinigameServiceAPI.SetGameData(serverAccount, dataKey, dataValue, VerifySuccess);
        }
 /// <summary>
 /// On level up, the user gains a little more max energy and their energy is refilled
 /// </summary>
 public void UserLeveledUp(ServerAccount account)
 {
     GetCurrentEnergyData(account, delegate(float energy, float maxEnergy, DateTime rechargeDate)
     {
         // not worried about this silly chain of messages because the client isn't waiting on it
         float newMaxEnergy = maxEnergy + Energy.MAX_ENERGY_INCREASE_PER_LEVEL;
         FashionMinigameServiceAPI.SetGameData(account, PLAYER_MAX_ENERGY, newMaxEnergy,
                                               delegate(XmlDocument maxEnergyResult)
         {
             FashionMinigameServer.VerifySuccess(maxEnergyResult);
             FashionMinigameServiceAPI.SetGameData(account, ENERGY_REGEN_DATE, DateTime.UtcNow,
                                                   delegate(XmlDocument dateResult)
             {
                 FashionMinigameServer.VerifySuccess(dateResult);
                 FashionMinigameServiceAPI.SetGameData(account, PLAYER_ENERGY_KEY, newMaxEnergy.ToString(),
                                                       delegate(XmlDocument currentEnergyResult)
                 {
                     FashionMinigameServer.VerifySuccess(currentEnergyResult);
                 });
             });
         });
     });
 }
 /// <summary>
 /// Directly sets the amount of energy in the database without any bounds or other safety checks.
 /// Only to be used on values after they've been verified
 /// </summary>
 private void SetEnergy(ServerAccount account, float energy)
 {
     FashionMinigameServiceAPI.SetGameData(account, PLAYER_ENERGY_KEY, energy.ToString(), FashionMinigameServer.VerifySuccess);
 }
 private void SetEnergyRegenDate(ServerAccount account, DateTime time)
 {
     FashionMinigameServiceAPI.SetGameData(account, ENERGY_REGEN_DATE, time.ToString(), FashionMinigameServer.VerifySuccess);
 }
Beispiel #6
0
        private void SetLevelComplete(Message message, Guid sessionId)
        {
            mLogger.Debug("SetLevelComplete: " + message.ToString());

            if (message.Data.Count < 4)

            {
                mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 3, actual was " + message.Data.Count);
                return;
            }

            int  totalXP             = CheckType.TryAssignType <int>(message.Data[1]);
            int  XPEarnedOnThisLevel = CheckType.TryAssignType <int>(message.Data[2]);
            bool leveledUp           = CheckType.TryAssignType <bool>(message.Data[3]);

            ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);

            // Save experience to the database
            FashionMinigameServiceAPI.SetGameData(serverAccount, GameDataKeys.PLAYER_EXPERIENCE_KEY, totalXP.ToString(), VerifySuccess);

            // Reward coins for experience
            int coinsEarned          = Rewards.GetCoinsFromExperience(XPEarnedOnThisLevel);
            NameValueCollection args = new NameValueCollection();

            args.Add("userId", mServerStateMachine.PaymentItemsManager.GetPaymentItemsUserId(sessionId));
            args.Add("amount", coinsEarned.ToString());
            args.Add("ipAddress", mServerStateMachine.ServerMessageProcessor.ServerReflector.GetClientIPAddress(sessionId));

            PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage();
            PaymentCommand cmd = clientMessage.AddVirtualCoinForUser(args);

            mServerStateMachine.PaymentItemsManager.ProcessPaymentCommand(cmd, delegate(string response)
            {
                XmlDocument xmlResponse = new XmlDocument();
                xmlResponse.LoadXml(response);
                mLogger.Debug("SetLevelComplete success: " + response);
                XmlElement vcoinNode = (XmlElement)xmlResponse.SelectSingleNode("//accounts/account[@currencyName='VCOIN']");

                // Convert to double, cast to int and then back to string to strip off decimal points
                string totalCoins = String.Empty;
                if (vcoinNode != null)
                {
                    totalCoins = ((int)Double.Parse(vcoinNode.GetAttribute("balance"))).ToString();
                }

                Hangout.Shared.Action resultMessage = delegate()
                {
                    // Return a message to the user with the results of SetLevelComplete
                    List <object> data = new List <object>();
                    data.Add(message.Data[0]);                     // callback id
                    data.Add(coinsEarned.ToString());
                    data.Add(totalCoins);
                    Message responseMessage = new Message(MessageType.FashionMinigame, data);
                    SendMessageToClient(responseMessage, sessionId);
                };
            });

            // Award friends a fraction of earned coins for working in this show
            int friendEscrowCoins = Rewards.GetFriendCoins(XPEarnedOnThisLevel, serverAccount.EntourageSize);

            if (friendEscrowCoins > 0)
            {
                EscrowManager.GiveFashionMinigameHiredFriendsCoins(serverAccount, friendEscrowCoins);
            }

            if (leveledUp)
            {
                mEnergyManager.UserLeveledUp(serverAccount);
            }
        }