Esempio n. 1
0
        public override void Update(UpdateState state)
        {
            var targElem = (int)Math.Ceiling(OverallPercent * Divisors.Length);

            Console.WriteLine(targElem);
            if (targElem > ActiveElem && CanFireNext)
            {
                //fire the next
                if (ActiveElem % 2 == 0)
                {
                    //firing an odd
                    OddTransition = 1f;
                    GameFacade.Screens.Tween.To(this, 0.5f, new Dictionary <string, float>()
                    {
                        { "OddTransition", 0f }
                    }, TweenElastic.EaseOut);
                }
                else
                {
                    EvenTransition = 1f;
                    GameFacade.Screens.Tween.To(this, 0.5f, new Dictionary <string, float>()
                    {
                        { "EvenTransition", 0f }
                    }, TweenElastic.EaseOut);
                }
                ActiveElem++;
                CanFireNext = false;
                GameThread.SetTimeout(() => { CanFireNext = true; }, 260);
            }
            base.Update(state);
        }
        public void HoverTile(int x, int y)
        {
            //Slight delay
            CurrentHoverLot.Value = null;
            if (HoverTimeout != null)
            {
                HoverTimeout.Clear();
            }

            if (Realestate.IsPurchasable((ushort)x, (ushort)y))
            {
                HoverTimeout = GameThread.SetTimeout(() =>
                {
                    var id       = MapCoordinates.Pack((ushort)x, (ushort)y);
                    var occupied = IsTileOccupied(x, y);
                    DataService.Get <Lot>(id).ContinueWith(lot =>
                    {
                        CurrentHoverLot.Value = lot.Result;

                        //Not loaded yet
                        if (lot.Result.Lot_Price == 0)
                        {
                            if (occupied)
                            {
                                DataService.Request(MaskedStruct.MapView_RollOverInfo_Lot, id);
                            }
                            else
                            {
                                DataService.Request(MaskedStruct.MapView_RollOverInfo_Lot_Price, id);
                            }
                        }
                    });
                }, 250);
            }
        }
Esempio n. 3
0
        public void ChangeTopic()
        {
            List <ITopic> topics = new List <ITopic>();

            if (View.Visible && AvatarId != 0)
            {
                topics.Add(Topics.For(MaskedStruct.SimPage_Main, AvatarId));
                switch (View.CurrentTab)
                {
                case UIPersonPageTab.Description:
                    topics.Add(Topics.For(MaskedStruct.SimPage_DescriptionPanel, AvatarId));
                    break;

                case UIPersonPageTab.Accomplishments:
                    topics.Add(Topics.For(MaskedStruct.SimPage_SkillsPanel, AvatarId));
                    topics.Add(Topics.For(MaskedStruct.SimPage_JobsPanel, AvatarId));
                    break;

                case UIPersonPageTab.Relationships:
                    //if we're due a relationship poll on our own avatar, perform it.
                    if (MyRelDirty)
                    {
                        MyRelDirty = false;
                        DataService.Request(MaskedStruct.FriendshipWeb_Avatar, Network.MyCharacter);
                        MyRelPollTimeout = GameThread.SetTimeout(() => { MyRelDirty = true; }, 60000);
                    }
                    break;
                }
            }
            Topic.Set(topics);
        }
Esempio n. 4
0
        public void Close()
        {
            Closing = true;
            GameThread.SetTimeout(() =>
            {
                ProgressDiag.DiagSide = UIDiagonalStripeSide.LEFT;
                TextDiag.DiagSide     = UIDiagonalStripeSide.RIGHT;
                GameFacade.Screens.Tween.To(this, 0.5f, new Dictionary <string, float>()
                {
                    { "InterpolatedAnimation", 0f }
                }, TweenQuad.EaseOut);
                GameFacade.Screens.Tween.To(Logo, 0.5f, new Dictionary <string, float>()
                {
                    { "Y", -200f }
                }, TweenQuad.EaseIn);
                GameFacade.Screens.Tween.To(Bg, 0.5f, new Dictionary <string, float>()
                {
                    { "Opacity", 0f }
                }, TweenQuad.EaseOut);

                GameThread.SetTimeout(() =>
                {
                    ProgressDiag.Parent.Remove(ProgressDiag);
                    TextDiag.Parent.Remove(TextDiag);
                    Logo.Parent.Remove(Logo);
                    LoadProgress.Parent.Remove(LoadProgress);
                    Bg.Parent.Remove(Bg);
                }, 500);
            }, 750);
        }
Esempio n. 5
0
 private void RateSwitch(UIElement button)
 {
     if (MayorIsMe || GameFacade.EnableMod)
     {
         CurrentMayorTab = UINeighMayorTabMode.Actions;
         Redraw();
     }
     else
     {
         FindController <CoreGameScreenController>()?.NeighborhoodProtocol?.BeginRating
             (CurrentNeigh.Value?.Id ?? 0,
             CurrentNeigh.Value?.Neighborhood_MayorID ?? 0,
             (success) =>
         {
             if (success == Server.Protocol.Electron.Packets.NhoodResponseCode.SUCCESS)
             {
                 UIAlert.Alert("", GameFacade.Strings.GetString("f115", "97"), true);
             }
             GameThread.SetTimeout(() =>
             {
                 RefreshMayor();
             }, 500);
         });
     }
 }
Esempio n. 6
0
 public void Invoke(Callback callback)
 {
     if (ThreadTimeout != null)
     {
         ThreadTimeout.Clear();
     }
     ;
     ThreadTimeout = GameThread.SetTimeout(callback, Timeout);
 }
Esempio n. 7
0
 public void Kill()
 {
     GameFacade.Screens.Tween.To(this, 0.3f, new Dictionary <string, float>()
     {
         { "Y", -60f }
     }, TweenQuad.EaseIn);
     GameThread.SetTimeout(() => Parent.Remove(this), 300);
     Dead = true;
 }
Esempio n. 8
0
 public virtual void Kill()
 {
     GameFacade.Screens.Tween.To(this, 0.3f, new Dictionary <string, float>()
     {
         { "Opacity", 0f }
     });
     GameThread.SetTimeout(() =>
     {
         Parent.Remove(this);
     }, 300);
 }
Esempio n. 9
0
 public void Kill()
 {
     GameFacade.Screens.Tween.To(Label, 0.4f, new Dictionary <string, float>()
     {
         { "Y", -100f }
     }, TweenQuad.EaseIn);
     GameFacade.Screens.Tween.To(this, 0.4f, new Dictionary <string, float>()
     {
         { "Alpha", 0f }
     }, TweenQuad.EaseIn);
     GameThread.SetTimeout(() => { Parent.Remove(this); }, 400);
 }
        public void Kill()
        {
            EnterLot.Opacity = 0.99f; //force an unpressable state
            More.Opacity     = 0.99f;
            var screen = GameFacade.Screens.CurrentUIScreen;

            GameFacade.Screens.Tween.To(this, 0.5f, new Dictionary <string, float>()
            {
                { "X", (screen.ScreenWidth / -2) - 32 }
            }, TweenQuad.EaseIn);
            GameThread.SetTimeout(() => { Parent.Remove(this); }, 500);
        }
        private void JoinLotRegulator_OnTransition(string transition, object data)
        {
            GameThread.InUpdate(() =>
            {
                switch (transition)
                {
                case "UnexpectedDisconnect":
                    //todo: what if we disconnect from lot but not city? the reverse?
                    break;

                case "Disconnected":
                    Screen.CleanupLastWorld();
                    if (ReconnectLotID != 0)
                    {
                        GameThread.SetTimeout(() => {
                            if (ReconnectLotID != 0)
                            {
                                JoinLot(ReconnectLotID);
                            }
                        }, 100);
                    }
                    //destroy the currently active lot (if possible)
                    break;

                case "PartiallyConnected":
                    Screen.InitializeLot();
                    Screen.vm.MyUID = Network.MyCharacter;
                    //initialize a lot
                    break;

                case "LotCommandStream":
                    //forward the command to the VM
                    //doesn't really need to be next update... but we don't want to catch the VM in a half-init state.
                    if (data == null)
                    {
                        break;
                    }
                    VMNetMessage msg = null;
                    if (data is FSOVMTickBroadcast)
                    {
                        msg = new VMNetMessage(VMNetMessageType.BroadcastTick, ((FSOVMTickBroadcast)data).Data);
                    }
                    else
                    {
                        msg = new VMNetMessage(VMNetMessageType.Direct, ((FSOVMDirectToClient)data).Data);
                    }

                    Screen.Driver?.ServerMessage(msg);
                    break;
                }
            });
        }
Esempio n. 12
0
 public void RetireAvatar(string cityName, uint avatarId)
 {
     ChangeState <TransitionScreen, ConnectCityController>((view, controller) =>
     {
         controller.Connect(cityName, avatarId, () => {
             var network = Kernel.Get <Network.Network>();
             network.CityClient.Write(new AvatarRetireRequest());
             GameThread.SetTimeout(() =>
             {
                 Disconnect();
             }, 1000);
         }, new Common.Utils.Callback(Disconnect));
     });
 }
Esempio n. 13
0
        public void Show(uint avatarId)
        {
            View.TrySaveDescription();
            AvatarId = avatarId;

            DataService.Get <Avatar>(avatarId).ContinueWith(x =>
            {
                View.CurrentAvatar.Value = x.Result;
            });
            DataService.Request(MaskedStruct.MyAvatar, avatarId);

            if (View.MyAvatar.Value == null)
            {
                DataService.Get <Avatar>(Network.MyCharacter).ContinueWith(x =>
                {
                    View.MyAvatar.Value = x.Result;
                    if (x.Result != null && x.Result.Avatar_LotGridXY != 0 && (View.MyLot.Value == null || View.MyLot.Value.Lot_Location_Packed != x.Result.Avatar_LotGridXY))
                    {
                        DataService.Request(MaskedStruct.AdmitInfo_Lot, x.Result.Avatar_LotGridXY).ContinueWith(y =>
                        {
                            View.MyLot.Value = (Lot)y.Result;
                        });
                    }
                });
            }
            else
            {
                if (View.MyAvatar.Value != null && View.MyAvatar.Value.Avatar_LotGridXY != 0 && (View.MyLot.Value == null || View.MyLot.Value.Lot_Location_Packed != View.MyAvatar.Value.Avatar_LotGridXY))
                {
                    DataService.Request(MaskedStruct.AdmitInfo_Lot, View.MyAvatar.Value.Avatar_LotGridXY).ContinueWith(y =>
                    {
                        View.MyLot.Value = (Lot)y.Result;
                    });
                }
            }

            //if we're due a relationship poll on our own avatar, perform it.
            if (MyRelDirty)
            {
                MyRelDirty = false;
                DataService.Request(MaskedStruct.FriendshipWeb_Avatar, Network.MyCharacter);
                MyRelPollTimeout = GameThread.SetTimeout(() => { MyRelDirty = true; }, 60000);
            }

            View.CurrentTab = UIPersonPageTab.Description;
            View.SetOpen(false);
            View.Parent.Add(View);
            View.Visible = true;
            ChangeTopic();
        }
 public void Kill(bool success)
 {
     if (success)
     {
         Step = 1f;
     }
     GameFacade.Screens.Tween.To(this, 0.3f, new Dictionary <string, float>()
     {
         { "Opacity", 0f },
         { "ScaleX", ScaleX * (success?1.5f:0.8f) },
         { "ScaleY", (success ? 1.5f : 0.8f) },
         { "X", X + (180 - 180 * (success ? 1.5f : 0.8f)) },
         { "Y", Y + (180 - 180 * (success ? 1.5f : 0.8f)) }
     }, TweenQuad.EaseIn);
     GameThread.SetTimeout(() => Parent.Remove(this), 300);
 }
Esempio n. 15
0
 public void Kill()
 {
     foreach (var child in Children)
     {
         GameFacade.Screens.Tween.To(child, 0.3f, new Dictionary <string, float>()
         {
             { "Opacity", 0f }
         }, TweenQuad.EaseOut);
     }
     GameFacade.Screens.Tween.To(this, 0.3f, new Dictionary <string, float>()
     {
         { "Opacity", 0f }
     }, TweenQuad.EaseOut);
     OnEnd?.Invoke();
     GameThread.SetTimeout(() => Parent.Remove(this), 300);
 }
Esempio n. 16
0
        public void DisplayChange(int change)
        {
            var newLabel = new UILabel();

            newLabel.Y                  = -20f;
            newLabel.CaptionStyle       = MoneyLabel.CaptionStyle.Clone();
            newLabel.CaptionStyle.Size  = 15;
            newLabel.CaptionStyle.Color = (change > 0) ? UIStyle.Current.PosMoney : UIStyle.Current.NegMoney;
            newLabel.Alignment          = FSO.Client.UI.Framework.TextAlignment.Right | FSO.Client.UI.Framework.TextAlignment.Middle;
            newLabel.Size               = new Microsoft.Xna.Framework.Vector2(128, 24);

            newLabel.Caption = ((change > 0) ? "+" : "-") + "§" + Math.Abs(change);
            Add(newLabel);

            GameFacade.Screens.Tween.To(newLabel, 1.5f, new Dictionary <string, float>()
            {
                { "Y", -50 }, { "Opacity", 0 }
            });
            GameThread.SetTimeout(() => { Remove(newLabel); }, 1500);
        }
        protected override void OnBeforeTransition(RegulatorState oldState, RegulatorState newState, object data)
        {
            switch (newState.Name)
            {
            case "SelectCity":
                //TODO: Do this on logout / disconnect rather than on connect
                ResetGame();

                var shard = data as ShardSelectorServletRequest;
                if (shard == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }

                this.AsyncTransition("ConnectToCitySelector", shard);
                break;

            case "ConnectToCitySelector":
                shard               = data as ShardSelectorServletRequest;
                CurrentShard        = shard;
                ShardSelectResponse = CityApi.ShardSelectorServlet(shard);
                this.AsyncProcessMessage(ShardSelectResponse);
                break;

            case "CitySelected":
                this.AsyncProcessMessage(data);
                break;

            case "OpenSocket":
                ReestablishAttempt = 0;
                var settings = data as ShardSelectorServletResponse;
                if (settings == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }
                else
                {
                    //101 is plain
                    LastSettings = settings;
                    Client.Connect(settings.Address + "101");
                }
                break;

            case "SocketOpen":
                break;

            case "RequestClientSession":
                Client.Write(new RequestClientSessionResponse {
                    Password = ShardSelectResponse.Ticket,
                    User     = ShardSelectResponse.AvatarID.ToString()
                });
                break;

            case "HostOnline":
                ((ClientShards)Shards).CurrentShard = Shards.GetByName(CurrentShard.ShardName).Id;

                Client.Write(
                    new ClientOnlinePDU {
                },
                    new SetIgnoreListPDU {
                    PlayerIds = new List <uint>()
                },
                    new SetInvinciblePDU {
                    Action = 0
                }
                    );
                AsyncTransition("PartiallyConnected");
                break;

            case "PartiallyConnected":
                if (Mode == CityConnectionMode.NORMAL)
                {
                    AsyncTransition("AskForAvatarData");
                }
                break;

            case "CompletePartialConnection":
                var shardRequest = (ShardSelectorServletRequest)data;
                if (shardRequest.ShardName != CurrentShard.ShardName)
                {
                    //Should never get into this state
                    throw new Exception("You cant complete a partial connection for a different city");
                }
                CurrentShard = shardRequest;
                AsyncTransition("AskForAvatarData");
                break;

            case "AskForAvatarData":
                DB.LoadAvatarById(new LoadAvatarByIDRequest
                {
                    AvatarId = uint.Parse(CurrentShard.AvatarID)
                }).ContinueWith(x =>
                {
                    if (x.IsFaulted)
                    {
                        ThrowErrorAndReset(new Exception("Failed to load avatar from db"));
                    }
                    else
                    {
                        AsyncProcessMessage(x.Result);
                    }
                });
                break;

            case "ReceivedAvatarData":
                AsyncTransition("AskForCharacterData");
                break;

            case "AskForCharacterData":
                DataService.Request(MaskedStruct.MyAvatar, uint.Parse(CurrentShard.AvatarID)).ContinueWith(x =>
                {
                    if (x.IsFaulted)
                    {
                        ThrowErrorAndReset(new Exception("Failed to load character from db"));
                    }
                    else
                    {
                        AsyncTransition("ReceivedCharacterData");
                    }
                });
                break;

            case "ReceivedCharacterData":
                //For now, we will call this connected
                AsyncTransition("Connected");
                break;

            case "Connected":
                CanReestablish = true;
                break;

            case "UnexpectedDisconnect":
                if (ReestablishAttempt > 0 || !CanReestablish)
                {
                    FSOFacade.Controller.FatalNetworkError(23);
                }
                else
                {
                    AsyncTransition("Reestablish");
                }
                break;

            case "Reestablish":
                ReestablishAttempt++;
                Client.Connect(LastSettings.Address + "101");
                break;

            case "Reestablishing":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = ShardSelectResponse.Ticket,
                    User     = ShardSelectResponse.AvatarID,
                    Unknown2 = 1
                });
                break;

            case "Reestablished":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );
                ReestablishAttempt = 0;
                AsyncTransition("Connected");
                break;

            case "ReestablishFail":
                if (ReestablishAttempt < 10 && CanReestablish)
                {
                    GameThread.SetTimeout(() =>
                    {
                        if (CurrentState?.Name == "ReestablishFail")
                        {
                            AsyncTransition("Reestablish");
                        }
                    }, 1000);
                }
                else
                {
                    AsyncTransition("UnexpectedDisconnect");
                }
                break;

            case "Disconnect":
                ShardSelectResponse = null;
                if (Client.IsConnected)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();
                }
                else
                {
                    AsyncTransition("Disconnected");
                }
                break;

            case "Reconnect":
                ShardSelectResponse = null;
                if (Client.IsConnected)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();
                }
                else
                {
                    AsyncTransition("Reconnecting");
                }
                break;

            case "Reconnecting":
                AsyncProcessMessage(CurrentShard);

                break;

            case "Disconnected":
                ((ClientShards)Shards).CurrentShard = null;
                ReestablishAttempt = 0;
                CanReestablish     = false;
                break;
            }
        }
Esempio n. 18
0
        private void Price_OnChange(UIElement element)
        {
            var input = (UITextEdit)element;
            var price = input.CurrentText;

            var isValid = VMEODRackOwnerPlugin.PRICE_VALIDATION.IsMatch(price);

            if (!isValid)
            {
                //TODO: Text box does not seem to like been updated in the update event loop, fix this
                return;

                /*for (var i = 0; i < price.Length; i++) {
                 *  if (!Char.IsDigit(price[i])) {
                 *      price = price.Substring(i, 1);
                 *      i--;
                 *  }
                 * }
                 *
                 * if (price.Length == 0) { price = "1"; }
                 * if (price[0] == '0') {
                 *  price = "1" + price.Substring(1);
                 * }
                 *
                 * input.CurrentText = price;*/
            }

            //Mark as dirty
            var newSalePrice = -1;

            if (!int.TryParse(price, out newSalePrice))
            {
                return;
            }

            var buttonIndex = Array.IndexOf(OutfitPrices, input);

            if (buttonIndex == -1)
            {
                return;
            }

            var priceIndex = GetPriceIndex(buttonIndex);

            if (priceIndex == -1)
            {
                return;
            }

            var outfit = Stock[priceIndex];

            //Which outfit is this for?
            lock (DirtyPrices)
            {
                DirtyPrices[outfit.outfit_id] = newSalePrice;
            }

            if (DirtyTimeout != null)
            {
                DirtyTimeout.Clear();
            }

            DirtyTimeout = GameThread.SetTimeout(() => FlushDirtyPrices(), 2000);
        }
Esempio n. 19
0
        private void ShowLotBuyDialog(Lot lot)
        {
            GameThread.InUpdate(() =>
            {
                GameFacade.Cursor.SetCursor(Common.Rendering.Framework.CursorType.Hourglass);
                if (_LotBuyAlert != null)
                {
                    return;
                }
                _LotBuyAlert = new UIAlert(new UIAlertOptions()
                {
                    Title = "", Message = ""
                });                                                                            //just fill this space til we spawn the dialog.
                _BuyLot = lot;
                Parent.Screen.CityTooltipHitArea.HideTooltip();

                var price   = lot.Lot_Price;
                var ourCash = Parent.Screen.VisualBudget;


                DataService.Request(MaskedStruct.SimPage_Main, Network.MyCharacter).ContinueWith(x =>
                {
                    var avatar = x.Result as Avatar;
                    if (!x.IsFaulted && avatar != null && avatar.Avatar_LotGridXY != 0)
                    {
                        //we already have a lot. We need to show the right dialog depending on whether or not we're owner.
                        var oldID = avatar.Avatar_LotGridXY;
                        DataService.Request(MaskedStruct.PropertyPage_LotInfo, oldID).ContinueWith(y =>
                        {
                            GameThread.SetTimeout(() => //setting a timeout here because for some reason when the request finishes we might not have all of the data yet...
                            {
                                GameFacade.Cursor.SetCursor(Common.Rendering.Framework.CursorType.Normal);
                                bool canBuy = true;
                                if (!y.IsFaulted && y.Result != null)
                                {
                                    var old = (Lot)y.Result;
                                    UIAlertOptions AlertOptions = new UIAlertOptions();
                                    if (old.Lot_LeaderID == Network.MyCharacter)
                                    {
                                        //we are the owner
                                        var oldVal   = old.Lot_Price;
                                        var moveFee  = 2000;
                                        var moveCost = moveFee + price;

                                        canBuy = (moveCost - oldVal) <= ourCash;
                                        if (old.Lot_RoommateVec.Count > 1)
                                        {
                                            //we have other roommates.
                                            AlertOptions.Title   = GameFacade.Strings.GetString("215", "10");
                                            AlertOptions.Message = GameFacade.Strings.GetString("215", "12",
                                                                                                new string[] { "$" + price.ToString(), "$" + ourCash.ToString(), "$" + moveCost.ToString(), "$" + moveFee.ToString(), "$" + oldVal.ToString() });
                                            AlertOptions.Buttons = new UIAlertButton[] {
                                                new UIAlertButton(UIAlertButtonType.Yes, (button) => { MoveLot(false); }, GameFacade.Strings.GetString("215", "14")),
                                                new UIAlertButton(UIAlertButtonType.Cancel, BuyPropertyAlert_OnCancel)
                                            };
                                        }
                                        else
                                        {
                                            //we live alone
                                            AlertOptions.Title   = GameFacade.Strings.GetString("215", "10");
                                            AlertOptions.Message = GameFacade.Strings.GetString("215", "16",
                                                                                                new string[] { "$" + price.ToString(), "$" + ourCash.ToString(), "$" + moveCost.ToString(), "$" + moveFee.ToString(), "$" + oldVal.ToString() });
                                            AlertOptions.Buttons = new UIAlertButton[] {
                                                new UIAlertButton(UIAlertButtonType.OK, (button) => { MoveLot(false); }, GameFacade.Strings.GetString("215", "17")),
                                                new UIAlertButton(UIAlertButtonType.Yes, (button) => { MoveLot(true); }, GameFacade.Strings.GetString("215", "18")),
                                                new UIAlertButton(UIAlertButtonType.Cancel, BuyPropertyAlert_OnCancel)
                                            };
                                        }
                                    }
                                    else
                                    {
                                        //we are a roommate.
                                        //can leave and start a new lot with no issue.
                                        canBuy               = price <= ourCash;
                                        AlertOptions.Title   = GameFacade.Strings.GetString("215", "10");
                                        AlertOptions.Message = GameFacade.Strings.GetString("215", "20", new string[] { "$" + price.ToString(), "$" + ourCash.ToString() });
                                        AlertOptions.Buttons = new UIAlertButton[] {
                                            new UIAlertButton(UIAlertButtonType.Yes, (btn) => {
                                                UIScreen.RemoveDialog(_LotBuyAlert);
                                                _LotBuyAlert = UIScreen.GlobalShowAlert(new UIAlertOptions()
                                                {
                                                    Message = GameFacade.Strings.GetString("211", "57"),
                                                    Buttons = new UIAlertButton[0]
                                                }, true);
                                                Parent.MoveMeOut(oldID, (result) => {
                                                    if (result)
                                                    {
                                                        BuyPropertyAlert_OnButtonClick(btn);
                                                    }
                                                });
                                            }),
                                            new UIAlertButton(UIAlertButtonType.No, BuyPropertyAlert_OnCancel)
                                        };
                                    }

                                    AlertOptions.Width = 600;
                                    _LotBuyAlert       = UIScreen.GlobalShowAlert(AlertOptions, true);
                                    UIButton toDisable;
                                    if (_LotBuyAlert.ButtonMap.TryGetValue(UIAlertButtonType.OK, out toDisable))
                                    {
                                        toDisable.Disabled = !canBuy;
                                    }
                                    if (_LotBuyAlert.ButtonMap.TryGetValue(UIAlertButtonType.Yes, out toDisable))
                                    {
                                        toDisable.Disabled = !canBuy;
                                    }
                                }
                                else
                                {
                                    canBuy = price <= ourCash;
                                    ShowNormalLotBuy("$" + price.ToString(), "$" + ourCash.ToString());
                                    UIButton toDisable;
                                    if (_LotBuyAlert.ButtonMap.TryGetValue(UIAlertButtonType.Yes, out toDisable))
                                    {
                                        toDisable.Disabled = !canBuy;
                                    }
                                }
                            }, 100);
                        });
                    }
                    else
                    {
                        //we don't have a lot
                        _LotBuyAlert = null;
                        ShowNormalLotBuy("$" + price.ToString(), "$" + ourCash.ToString());
                        var canBuy = price <= ourCash;
                        UIButton toDisable;
                        if (_LotBuyAlert.ButtonMap.TryGetValue(UIAlertButtonType.Yes, out toDisable))
                        {
                            toDisable.Disabled = !canBuy;
                        }
                        GameFacade.Cursor.SetCursor(Common.Rendering.Framework.CursorType.Normal);
                    }
                });
            });
        }
Esempio n. 20
0
        protected override void OnAfterTransition(RegulatorState oldState, RegulatorState newState, object data)
        {
            switch (newState.Name)
            {
            case "SelectLot":
                IsDisconnecting = false;
                AsyncTransition("FindLot", data);
                break;

            case "FindLot":
                //LotId = ((JoinLotRequest)data).LotId;
                City.Write(new FSO.Server.Protocol.Electron.Packets.FindLotRequest {
                    LotId = ((JoinLotRequest)data).LotId
                });
                break;

            case "FoundLot":
                var result = (FindLotResponse)data;
                if (result.Status == Server.Protocol.Electron.Model.FindLotResponseStatus.FOUND)
                {
                    LotId           = result.LotId;
                    FindLotResponse = result;
                    AsyncTransition("OpenSocket", result.Address);
                }
                else
                {
                    ThrowErrorAndReset(result.Status);
                }
                break;

            case "OpenSocket":
                ReestablishAttempt = 0;
                var address = data as string;
                LastAddress = address;
                if (address == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }
                else
                {
                    //101 is plain
                    Client.Connect(address + "101");
                }
                break;

            case "SocketOpen":
                break;

            case "RequestClientSession":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = FindLotResponse.LotServerTicket,
                    User     = FindLotResponse.User
                });
                break;

            case "HostOnline":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );

                AsyncTransition("PartiallyConnected");

                //When we join a property, get the lot info to update the thumbnail cache
                DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                break;

            case "UnexpectedDisconnect":
                if (ReestablishAttempt > 0)
                {
                    IsDisconnecting = true;
                    AsyncTransition("Disconnected");
                }
                else
                {
                    GameThread.SetTimeout(() =>
                    {
                        if (CurrentState?.Name == "UnexpectedDisconnect")
                        {
                            AsyncTransition("Reestablish");
                        }
                        else if (CurrentState?.Name != "Disconnected")
                        {
                            IsDisconnecting = true;
                            AsyncTransition("Disconnected");
                        }
                    }, 100);
                }
                break;

            case "Reestablish":
                ReestablishAttempt++;
                Client.Connect(LastAddress + "101");
                break;

            case "Reestablishing":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = FindLotResponse.LotServerTicket,
                    User     = FindLotResponse.User,
                    Unknown2 = 1
                });
                break;

            case "Reestablished":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );
                ReestablishAttempt = 0;
                AsyncTransition("LotCommandStream");
                break;

            case "ReestablishFail":
                if (ReestablishAttempt < 10)
                {
                    GameThread.SetTimeout(() =>
                    {
                        if (CurrentState?.Name == "ReestablishFail")
                        {
                            AsyncTransition("Reestablish");
                        }
                    }, 1000);
                }
                else
                {
                    AsyncTransition("UnexpectedDisconnect");
                }
                break;


            case "Disconnect":
                if (Client.IsConnected && !IsDisconnecting)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();

                    //When we leave a property, get the lot info to update the thumbnail cache
                    DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                }
                else
                {
                    AsyncTransition("Disconnected");
                }
                break;

            case "Disconnected":
                ReestablishAttempt = 0;
                break;
            }
        }