Exemplo n.º 1
0
        public override int run(string[] args)
        {
            shutdownOnInterrupt();
            try
            {
                string endpoint = string.Format("default:tcp -p {0}", ConfigMain.GetConfigValue(BaseCommon.CONFIGICEPORT));
                _ic = communicator();
                ObjectAdapter adapter = _ic.createObjectAdapterWithEndpoints("AASDataServer", endpoint);

                IceDataService dataService = new IceDataService();
                adapter.add(dataService, _ic.stringToIdentity("AASDataServer/DataServant"));
                adapter.activate();
                _isRunning = true;
                LogHelper.Instance.Info(Title + "已启动,端口:" + endpoint);
                _ic.waitForShutdown();
                if (interrupted())
                {
                    LogHelper.Instance.Info(Title + "已中断");
                    return(1);
                }
                LogHelper.Instance.Info(Title + "已停止");
                _isRunning = false;
                return(0);
            }
            catch (System.Exception ex)
            {
                _isRunning = false;
                LogHelper.Instance.Info(Title + "运行出错" + ex);
                return(1);
            }
        }
Exemplo n.º 2
0
        public static List <XIMWrapper> Transform(XMLTransformer transformer, List <DataSet> dataSetList)
        {
            if (transformer == null || dataSetList == null)
            {
                return(null);
            }
            List <XIMWrapper> resultList = new List <XIMWrapper>();

            foreach (DataSet ds in dataSetList)
            {
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = new StringWriter(sb);
                ds.WriteXml(sw);
                string xml = sb.ToString();

                string str = "";
                if (transformer.TransformString(xml, ref str))
                {
                    XIMWrapper w = new XIMWrapper(str);
                    w.GUIDList.Add(ConfigMain.GetGUID(ds));
                    resultList.Add(w);
                }
            }
            return(resultList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 登录判断
        /// </summary>
        private void Login()
        {
            string error = string.Empty;

            if (this.txtUserName.Text.Trim() != string.Empty && this.txtUserPwd.Text.Trim() != string.Empty)
            {
                bool result = true;//Program.DataServiceClient.LoginUser(this.txtUserName.Text.Trim(), this.txtUserPwd.Text.Trim(), out error);
                if (result == true)
                {
                    ConfigMain.SetConfigValue("userName", this.txtUserName.Text.Trim());
                    if (chkBoxPwd.Checked)
                    {
                        ConfigMain.SetConfigValue("userPwd", CommonUtils.EncryptDES(this.txtUserPwd.Text.Trim(), CommonUtils.encryptKey));
                    }
                    else
                    {
                        //ConfigMain.SetConfigValue("userPwd", "");
                        ConfigMain.removeItem("userPwd");
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show(error, "Error");
                }
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        /// <summary>Initialize the mod.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // Load configs
            this.Config         = helper.ReadConfig <ConfigMain>();
            this.TreasureConfig = helper.ReadJsonFile <ConfigTreasure>("treasure.json") ?? new ConfigTreasure();
            this.FishConfig     = helper.ReadJsonFile <ConfigFish>("fish.json") ?? new ConfigFish();

            // Make sure the extra configs are generated
            helper.WriteJsonFile("treasure.json", this.TreasureConfig);
            helper.WriteJsonFile("fish.json", this.FishConfig);

            this.Config.AdditionalLootChance = (float)Math.Min(this.Config.AdditionalLootChance, 0.99);
            helper.WriteConfig(this.Config);

            this.OnLanguageChange(LocalizedContentManager.CurrentLanguageCode);

            // Stop here if the mod is disabled
            if (!this.Config.ModEnabled)
            {
                return;
            }

            // Events
            GameEvents.UpdateTick    += this.UpdateTick;
            ControlEvents.KeyPressed += this.KeyPressed;
            LocalizedContentManager.OnLanguageChange += this.OnLanguageChange;
        }
Exemplo n.º 5
0
        private bool Bind()
        {
            try
            {
                int i = 1;

                socketPub.Bind(string.Format("tcp://*:{0}", ConfigMain.GetConfigValue(BaseCommon.CONFIGPUBPORT)));
                LogHelper.Instance.Info("pub数据端口:" + ConfigMain.GetConfigValue(BaseCommon.CONFIGPUBPORT));

                foreach (var item in dictMyZmq.Values)
                {
                    item.Socket.Connect(string.Format("tcp://{0}:{1}", item.Ip, item.Port));
                    LogHelper.Instance.Info(string.Format("Sub数据地址{0}:{1}:{2}", i, item.Ip, item.Port));
                    item.Socket.SubscribeAll();
                    Thread.Sleep(100);
                    i++;
                }
            }
            catch (System.Exception ex)
            {
                LogHelper.Instance.Info("异常:" + ex.ToString());
                return(false);
            }


            return(true);
        }
Exemplo n.º 6
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.dgLogs.ItemsSource = ocLog;
            port        = ConfigMain.GetConfigValue("ServicePort", "42808");
            serverIP    = ConfigMain.GetConfigValue("ServiceIp", "localhost");
            this.Title += string.Format(" [端口:{0}]", port);

            Task task = new Task(InitService);

            task.Start();
        }
Exemplo n.º 7
0
        public static int GetRandomFish(IEnumerable <KeyValuePair <int, FishData> > possibleFish)
        {
            ConfigMain config = ModFishing.INSTANCE.Config;

            possibleFish = possibleFish.ToList();

            if (!config.ConfigLegendaries)
            {
                possibleFish = possibleFish.Where(e => !FishHelper.IsLegendary(e.Key));
            }

            return(!possibleFish.Any() ? FishHelper.GetRandomTrash() : possibleFish.Select(e => new KeyValuePair <int, double>(e.Key, e.Value.Chance)).Choose(Game1.random));
        }
Exemplo n.º 8
0
        private bool Bind()
        {
            try
            {
                contextPubMarket = new ZContext();
                contextSubMarket = new ZContext();
                contextPubTran   = new ZContext();
                contextSubTran   = new ZContext();

                socketPubMarket = new ZSocket(contextPubMarket, ZSocketType.PUB);
                socketSubMarket = new ZSocket(contextSubMarket, ZSocketType.SUB);
                socketPubTran   = new ZSocket(contextPubTran, ZSocketType.PUB);
                socketSubTran   = new ZSocket(contextSubTran, ZSocketType.SUB);

                socketPubMarket.Bind(string.Format("tcp://*:{0}", ConfigMain.GetConfigValue(BaseCommon.CONFIGMARKETPUBPORT)));
                LogHelper.Instance.Info("pubMarket数据端口:" + ConfigMain.GetConfigValue(BaseCommon.CONFIGMARKETPUBPORT));
                //socketPubMarket.SendTimeout = TimeSpan.FromSeconds(60);

                //socketSubMarket.ReceiveTimeout = TimeSpan.FromSeconds(60);
                //socketSubMarket.ReconnectInterval = TimeSpan.FromSeconds(60);
                socketSubMarket.Connect(string.Format("tcp://{0}:{1}", ip, ConfigMain.GetConfigValue(BaseCommon.CONFIGMARKETSUBPORT)));
                LogHelper.Instance.Info("SubMarket数据端口:" + ip + ":" + ConfigMain.GetConfigValue(BaseCommon.CONFIGMARKETSUBPORT));
                socketSubMarket.SubscribeAll();


                socketPubTran.Bind(string.Format("tcp://*:{0}", ConfigMain.GetConfigValue(BaseCommon.CONFIGTRANSPUBPORT)));
                LogHelper.Instance.Info("pubTransaction数据端口:" + ConfigMain.GetConfigValue(BaseCommon.CONFIGTRANSPUBPORT));
                //socketPubTran.SendTimeout = TimeSpan.FromSeconds(60);

                //socketSubTran.ReceiveTimeout = TimeSpan.FromSeconds(60);
                //socketSubTran.ReconnectInterval = TimeSpan.FromSeconds(60);
                socketSubTran.Connect(string.Format("tcp://{0}:{1}", ip, ConfigMain.GetConfigValue(BaseCommon.CONFIGTRANSSUBPORT)));
                LogHelper.Instance.Info("SubTransaction数据端口:" + ip + ":" + ConfigMain.GetConfigValue(BaseCommon.CONFIGTRANSSUBPORT));
                socketSubTran.SubscribeAll();

                ////socketSubMarket.TcpKeepAlive = TcpKeepaliveBehaviour.Enable;
                ////socketPubMarket.TcpKeepAliveInterval = 60 * 1000;

                ////socketPubTran.TcpKeepAlive = TcpKeepaliveBehaviour.Enable;
                ////socketPubTran.TcpKeepAliveInterval = 60 * 1000;
            }
            catch (System.Exception ex)
            {
                LogHelper.Instance.Info("异常:" + ex.ToString());
                return(false);
            }


            return(true);
        }
Exemplo n.º 9
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     port = ConfigMain.GetConfigValue("ServicePort");
     if (string.IsNullOrEmpty(port))
     {
         port = "80";
     }
     serverIP = ConfigMain.GetConfigValue("ServiceIp");
     if (string.IsNullOrEmpty(serverIP))
     {
         serverIP = "localhost";
     }
     this.Text += string.Format(" [端口:{0}]", port);
     this.backgroundWorker1.RunWorkerAsync();
 }
Exemplo n.º 10
0
        public void RunWork()
        {
            ip = ConfigMain.GetConfigValue(BaseCommon.CONFIGIP);
            bool outErr = false;

            writeTxt  = bool.TryParse(ConfigMain.GetConfigValue(BaseCommon.CONFIGWRITETXT), out outErr);
            tranCache = new ConcurrentQueue <ZMessage>();
            tranCount = 0;
            dataCache = new ConcurrentQueue <ZMessage>();
            dataCount = 0;

            if (Bind())
            {
                pubMarketThread = new Thread(new ThreadStart(PubMarket))
                {
                    IsBackground = true
                };
                pubMarketThread.Start();

                subMarketThread = new Thread(new ThreadStart(SubMarket))
                {
                    IsBackground = true
                };
                subMarketThread.Start();

                pubTransThread = new Thread(new ThreadStart(PubTransaction))
                {
                    IsBackground = true
                };
                pubTransThread.Start();

                subTransThread = new Thread(new ThreadStart(SubTransaction))
                {
                    IsBackground = true
                };
                subTransThread.Start();
                if (writeTxt)
                {
                    //marketWriteCache = new ConcurrentQueue<ZMessage>();
                    //tranWriteCache = new ConcurrentQueue<ZMessage>();

                    //writeMarketThread = new Thread(new ThreadStart(WriteMarket)) { IsBackground = true };
                    //writeMarketThread.Start();
                    //writeTranThread = new Thread(new ThreadStart(WriteTran)) { IsBackground = true };
                    //writeTranThread.Start();
                }
            }
        }
Exemplo n.º 11
0
        private bool Init()
        {
            try
            {
                dictMyZmq = new Dictionary <string, MyZmq>();
                dataCache = new ConcurrentQueue <ZMessage>();

                ip   = ConfigMain.GetConfigValue(BaseCommon.CONFIGIP).Split(',');
                port = ConfigMain.GetConfigValue(BaseCommon.CONFIGSUBPORT).Split(',');
                if (ip.Length == 0 || port.Length == 0)
                {
                    return(false);
                }
                for (int i = 0; i < port.Length; i++)
                {
                    //if (i < ip.Length)
                    //{
                    //    MyZmq mq = new MyZmq();
                    //    mq.Ip = ip[i].Trim();
                    //    mq.Port = int.Parse(port[i].Trim());
                    //    mq.Socket = new ZSocket(new ZContext(), ZSocketType.SUB);
                    //    dictMyZmq.Add(string.Format("{0}:{1}", mq.Ip, mq.Port), mq);
                    //}
                    //else
                    //{
                    //    MyZmq mq = new MyZmq();
                    //    mq.Ip = ip[i - 1].Trim();
                    //    mq.Port = int.Parse(port[i].Trim());
                    //    mq.Socket = new ZSocket(new ZContext(), ZSocketType.SUB);
                    //    dictMyZmq.Add(string.Format("{0}:{1}", mq.Ip, mq.Port), mq);
                    //}
                    MyZmq mq = new MyZmq();
                    mq.Ip     = ip[0].Trim();
                    mq.Port   = int.Parse(port[i].Trim());
                    mq.Socket = new ZSocket(new ZContext(), ZSocketType.SUB);
                    dictMyZmq.Add(string.Format("{0}:{1}", mq.Ip, mq.Port), mq);
                }
                contextPub = new ZContext();
                socketPub  = new ZSocket(contextPub, ZSocketType.PUB);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.Error("Init:" + ex.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        private void FormLogin_Load(object sender, EventArgs e)
        {
            InitService();
            string userName = ConfigMain.GetConfigValue("userName");
            string userPwd  = ConfigMain.GetConfigValue("userPwd");

            if (userName != string.Empty && userPwd != string.Empty)
            {
                this.txtUserName.Text  = userName;
                this.txtUserPwd.Text   = CommonUtils.DecryptDES(userPwd, CommonUtils.encryptKey);
                this.chkBoxPwd.Checked = true;
            }
            else
            {
                chkBoxPwd.Checked = false;
            }
        }
Exemplo n.º 13
0
        private bool InitService()
        {
            if (Program.DataServiceClient != null)
            {
                return(true);
            }

            servicePort = ConfigMain.GetConfigValue("ServicePort");
            if (string.IsNullOrEmpty(servicePort))
            {
                MessageBox.Show("通讯连接端口为空", "Error");
            }
            serviceIp = ConfigMain.GetConfigValue("ServiceIp");
            if (string.IsNullOrEmpty(serviceIp))
            {
                MessageBox.Show("通讯连接IP为空", "Error");
            }
            string endPoint = string.Format("http://{0}:{1}/", serviceIp, servicePort);

            var httpBinding = new WSHttpBinding(SecurityMode.None);

            httpBinding.MaxReceivedMessageSize = 2147483647;
            httpBinding.ReceiveTimeout         = new TimeSpan(0, 0, 10);
            httpBinding.UseDefaultWebProxy     = false;

            EndpointIdentity ei = null;

            ei = EndpointIdentity.CreateDnsIdentity(serviceIp);
            var endpointAddress = new EndpointAddress(new Uri(endPoint), ei);

            Program.DataServiceClient = new DataServiceClient(httpBinding, endpointAddress);
            if (Program.DataServiceClient == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 14
0
        public static void StartMinigameEndFunction(FishingRod rod, int extra)
        {
            ModFishing.INSTANCE.Monitor.Log("Overriding fishing minigame", LogLevel.Trace);
            ConfigMain config   = ModFishing.INSTANCE.Config;
            SFarmer    lastUser = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <SFarmer>(rod, "lastUser");
            Vector2    bobber   = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <Vector2>(rod, "bobber");

            rod.isReeling = true;
            rod.hit       = false;
            switch (lastUser.FacingDirection)
            {
            case 1:
                lastUser.FarmerSprite.setCurrentSingleFrame(48, 32000, false, false);
                break;

            case 3:
                lastUser.FarmerSprite.setCurrentSingleFrame(48, 32000, false, true);
                break;
            }
            lastUser.FarmerSprite.pauseForSingleAnimation = true;

            int clearWaterDistance = FishingRod.distanceToLand((int)(bobber.X / (double)Game1.tileSize - 1.0), (int)(bobber.Y / (double)Game1.tileSize - 1.0), lastUser.currentLocation);

            FishingRodOverrides.ClearWaterDistances[lastUser] = clearWaterDistance;
            float num = 1f * (clearWaterDistance / 5f) * (Game1.random.Next(1 + Math.Min(10, lastUser.FishingLevel) / 2, 6) / 5f);

            if (rod.favBait)
            {
                num *= 1.2f;
            }
            float fishSize = Math.Max(0.0f, Math.Min(1f, num * (float)(1.0 + Game1.random.Next(-10, 10) / 100.0)));
            bool  treasure = false;

            double treasureChance = config.TreasureChance + lastUser.LuckLevel * config.TreasureLuckLevelEffect + (rod.getBaitAttachmentIndex() == 703 ? config.TreasureBaitEffect : 0.0) + (rod.getBobberAttachmentIndex() == 693 ? config.TreasureBobberEffect : 0.0) + Game1.dailyLuck * config.TreasureDailyLuckEffect + (lastUser.professions.Contains(9) ? config.TreasureChance : 0.0) + config.TreasureStreakEffect * FishHelper.GetStreak(lastUser);

            treasureChance = Math.Min(treasureChance, config.MaxTreasureChance);
            if (!Game1.isFestival() && lastUser.fishCaught != null && lastUser.fishCaught.Count > 1 && Game1.random.NextDouble() < treasureChance)
            {
                treasure = true;
            }

            // Override caught fish
            bool legendary = FishHelper.IsLegendary(extra);

            if (!config.UseVanillaFish && (!config.VanillaLegendaries || !legendary))
            {
                int origExtra = extra;
                extra = FishHelper.GetRandomFish(clearWaterDistance);
                if (FishHelper.IsTrash(extra))
                {
                    if (false) // TODO: Replace this with code relating to a config option that determines the chance you'll get fish/trash
                    {
#pragma warning disable CS0162 // Unreachable code detected
                        Game1.showGlobalMessage("No valid fish to catch! Giving junk instead.");
                        StardewValley.Object o = new StardewValley.Object(extra, 1, false, -1, 0);
                        rod.pullFishFromWater(extra, -1, 0, 0, false, false);
                        return;

#pragma warning restore CS0162 // Unreachable code detected
                    }
                    else
                    {
                        ModFishing.INSTANCE.Monitor.Log("No valid fish to catch! Using original fish instead.", LogLevel.Warn);
                        extra = origExtra;
                    }
                }
            }

            // Show custom bobber bar
            Game1.activeClickableMenu = new CustomBobberBar(lastUser, extra, fishSize, treasure, rod.attachments[1] != null ? rod.attachments[1].ParentSheetIndex : -1, clearWaterDistance);
        }
Exemplo n.º 15
0
        public CustomBobberBar(SFarmer user, int whichFish, float fishSize, bool treasure, int bobber, int waterDepth) : base(whichFish, fishSize, treasure, bobber)
        {
            this.User        = user;
            this._origStreak = FishHelper.GetStreak(user);

            /* Private field hooks */
            this._treasureField            = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <bool>(this, "treasure");
            this._treasureCaughtField      = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <bool>(this, "treasureCaught");
            this._treasurePositionField    = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "treasurePosition");
            this._treasureAppearTimerField = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "treasureAppearTimer");
            this._treasureScaleField       = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "treasureScale");

            this._distanceFromCatchingField = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "distanceFromCatching");
            this._treasureCatchLevelField   = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "treasureCatchLevel");

            this._bobberBarPosField = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "bobberBarPos");
            this._difficultyField   = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <float>(this, "difficulty");
            this._fishQualityField  = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <int>(this, "fishQuality");
            this._perfectField      = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <bool>(this, "perfect");

            this._sparkleTextField = ModFishing.INSTANCE.Helper.Reflection.GetPrivateField <SparklingText>(this, "sparkleText");

            this._lastDistanceFromCatching = this._distanceFromCatchingField.GetValue();
            this._lastTreasureCatchLevel   = this._treasureCatchLevelField.GetValue();

            /* Actual code */
            ConfigMain    config  = ModFishing.INSTANCE.Config;
            ConfigStrings strings = ModFishing.INSTANCE.Strings;

            // Choose a random fish, this time using the custom fish selector
            FishingRod rod = Game1.player.CurrentTool as FishingRod;
            //int waterDepth = rod != null ? ModEntry.INSTANCE.Helper.Reflection.GetPrivateValue<int>(rod, "clearWaterDistance") : 0;

            // Applies difficulty modifier, including if fish isn't paying attention
            float difficulty = this._difficultyField.GetValue() * config.BaseDifficultyMult;

            difficulty *= 1f + config.DifficultyStreakEffect * this._origStreak;
            double difficultyChance = config.UnawareChance + user.LuckLevel * config.UnawareLuckLevelEffect + Game1.dailyLuck * config.UnawareDailyLuckEffect;

            if (Game1.random.NextDouble() < difficultyChance)
            {
                Game1.showGlobalMessage(string.Format(strings.UnawareFish, 1f - config.UnawareMult));
                difficulty *= config.UnawareMult;
            }
            this._difficultyField.SetValue(difficulty);

            // Adjusts quality to be increased by streak
            int fishQuality = this._fishQualityField.GetValue();

            this._origQuality = fishQuality;
            int qualityBonus = (int)Math.Floor((double)this._origStreak / config.StreakForIncreasedQuality);

            fishQuality = Math.Min(fishQuality + qualityBonus, 3);
            if (fishQuality == 3)
            {
                fishQuality++;                   // Iridium-quality fish. Only possible through your perfect streak
            }
            this._fishQualityField.SetValue(fishQuality);

            // Increase the user's perfect streak (this will be dropped to 0 if they don't get a perfect catch)
            if (this._origStreak >= config.StreakForIncreasedQuality)
            {
                this._sparkleTextField.SetValue(new SparklingText(Game1.dialogueFont, string.Format(strings.StreakDisplay, this._origStreak), Color.Yellow, Color.White));
            }
            FishHelper.SetStreak(user, this._origStreak + 1);
        }
Exemplo n.º 16
0
        public CustomBobberBar(Farmer user, int whichFish, float fishSize, bool treasure, int bobber) : base(whichFish, fishSize, treasure, bobber)
        {
            this.User        = user;
            this._origStreak = ModFishing.Instance.Api.GetStreak(user);
            this._origFish   = whichFish;

            /* Private field hooks */
            this._treasure            = new ReflectedField <BobberBar, bool>(this, "treasure");
            this._treasure            = new ReflectedField <BobberBar, bool>(this, "treasure");
            this._treasureCaught      = new ReflectedField <BobberBar, bool>(this, "treasureCaught");
            this._treasurePosition    = new ReflectedField <BobberBar, float>(this, "treasurePosition");
            this._treasureAppearTimer = new ReflectedField <BobberBar, float>(this, "treasureAppearTimer");
            this._treasureScale       = new ReflectedField <BobberBar, float>(this, "treasureScale");

            this._distanceFromCatching = new ReflectedField <BobberBar, float>(this, "distanceFromCatching");
            this._treasureCatchLevel   = new ReflectedField <BobberBar, float>(this, "treasureCatchLevel");

            this._bobberBarPos    = new ReflectedField <BobberBar, float>(this, "bobberBarPos");
            this._bobberInBar     = new ReflectedField <BobberBar, bool>(this, "bobberInBar");
            this._difficulty      = new ReflectedField <BobberBar, float>(this, "difficulty");
            this._fishQuality     = new ReflectedField <BobberBar, int>(this, "fishQuality");
            this._perfect         = new ReflectedField <BobberBar, bool>(this, "perfect");
            this._scale           = new ReflectedField <BobberBar, float>(this, "scale");
            this._flipBubble      = new ReflectedField <BobberBar, bool>(this, "flipBubble");
            this._bobberBarHeight = new ReflectedField <BobberBar, int>(this, "bobberBarHeight");
            this._reelRotation    = new ReflectedField <BobberBar, float>(this, "reelRotation");
            this._bobberPosition  = new ReflectedField <BobberBar, float>(this, "bobberPosition");
            this._bossFish        = new ReflectedField <BobberBar, bool>(this, "bossFish");
            this._motionType      = new ReflectedField <BobberBar, int>(this, "motionType");
            this._fishSize        = new ReflectedField <BobberBar, int>(this, "fishSize");
            this._whichFish       = new ReflectedField <BobberBar, int>(this, "whichFish");

            this._barShake        = new ReflectedField <BobberBar, Vector2>(this, "barShake");
            this._fishShake       = new ReflectedField <BobberBar, Vector2>(this, "fishShake");
            this._treasureShake   = new ReflectedField <BobberBar, Vector2>(this, "treasureShake");
            this._everythingShake = new ReflectedField <BobberBar, Vector2>(this, "everythingShake");

            this._sparkleText = new ReflectedField <BobberBar, SparklingText>(this, "sparkleText");

            this._lastDistanceFromCatching = this._distanceFromCatching.Value;
            this._lastTreasureCatchLevel   = this._treasureCatchLevel.Value;

            /* Actual code */
            ConfigMain  config = ModFishing.Instance.MainConfig;
            IFishTraits traits = ModFishing.Instance.Api.GetFishTraits(whichFish);

            // Check if fish is unaware
            this.Unaware = Game1.random.NextDouble() < ModFishing.Instance.Api.GetUnawareChance(user, whichFish);

            // Applies difficulty modifier, including if fish is unaware
            float difficulty = traits?.Difficulty ?? this._difficulty.Value;

            difficulty *= config.DifficultySettings.BaseDifficultyMult;
            difficulty *= 1F + this._origStreak * config.DifficultySettings.DifficultyStreakEffect;
            if (this.Unaware)
            {
                difficulty *= config.UnawareSettings.UnawareMult;
                Game1.showGlobalMessage(ModFishing.Translate("text.unaware", ModFishing.Translate("text.percent", 1F - config.UnawareSettings.UnawareMult)));
            }
            this._difficulty.Value = difficulty;

            // Adjusts additional traits about the fish
            if (traits != null)
            {
                this._motionType.Value = (int)traits.MotionType;
                this._fishSize.Value   = traits.MinSize + (int)((traits.MaxSize - traits.MinSize) * fishSize) + 1;
            }

            // Adjusts quality to be increased by streak
            int fishQuality = this._fishQuality.Value;

            this._origQuality = fishQuality;
            int qualityBonus = (int)Math.Floor((double)this._origStreak / config.StreakSettings.StreakForIncreasedQuality);

            fishQuality = Math.Min(fishQuality + qualityBonus, 3);
            if (fishQuality == 3)
            {
                fishQuality++;                   // Iridium-quality fish. Only possible through your perfect streak
            }
            this._fishQuality.Value = fishQuality;

            // Increase the user's perfect streak (this will be dropped to 0 if they don't get a perfect catch)
            if (this._origStreak >= config.StreakSettings.StreakForIncreasedQuality)
            {
                this._sparkleText.Value = new SparklingText(Game1.dialogueFont, ModFishing.Translate("text.streak", this._origStreak), Color.Yellow, Color.White);
            }
        }
Exemplo n.º 17
0
        public bool SendQuotaData(JyDataSet.额度分配DataTable dtLimit, string serverMac)
        {
            try
            {
                if (dtLimit.Rows.Count == 0)
                {
                    Program.logger.LogInfo(string.Format("接收server-{0}的额度分配DataTable.Rows=0", serverMac));
                    return(false);
                }
                //判断当前MAC是否已经更新数据
                string    sqlMac = string.Format("select 更新日期 from dbo.日志表 where 服务器MAC='{0}' and 数据类型='额度'", serverMac);
                DataTable dtMac  = SQLHelper.ExecuteDt(sqlMac);
                if (dtMac.Rows.Count > 0)
                {
                    int cDate = Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd"));
                    if (cDate == Convert.ToInt32(dtMac.Rows[0]["更新日期"].ToString()))
                    {
                        string updateType = ConfigMain.GetConfigValue("UpdateType");
                        if ("0".Equals(updateType))
                        {
                            //删除原有server Mac的数据
                            string sqlDel = string.Format("delete from dbo.额度分配 where 服务器MAC='{0}' and 日期={1}", serverMac, Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd")));
                            SQLHelper.ExecuteSql(sqlDel);
                        }
                    }
                }

                StringBuilder             sb        = new StringBuilder();
                Dictionary <int, decimal> dictPrice = new Dictionary <int, decimal>();
                //sb.Append("begin ");
                Program.logger.LogInfo(string.Format("额度分配数据入库开始:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
                foreach (JyDataSet.额度分配Row 额度分配Row1 in dtLimit)
                {
                    decimal closePrice;
                    int     iCode = Convert.ToInt32(额度分配Row1.证券代码.Trim());
                    if (dictPrice.ContainsKey(iCode))
                    {
                        closePrice = dictPrice[iCode];
                    }
                    else
                    {
                        closePrice = CommonUtils.GetClosePrice(额度分配Row1.证券代码.Trim());
                    }
                    string sql = string.Format("insert into dbo.额度分配(交易员,证券代码,组合号,市场,证券名称,拼音缩写,买模式,卖模式,交易额度,手续费率,服务器MAC,收盘价,日期,分组)values('{0}','{1}','{2}',{3},'{4}','{5}',{6},{7},{8},{9},'{10}',{11},{12},'{13}');",
                                               额度分配Row1.交易员,
                                               额度分配Row1.证券代码,
                                               额度分配Row1.组合号,
                                               额度分配Row1.市场,
                                               额度分配Row1.证券名称,
                                               额度分配Row1.拼音缩写,
                                               额度分配Row1.买模式,
                                               额度分配Row1.卖模式,
                                               额度分配Row1.交易额度,
                                               额度分配Row1.手续费率,
                                               serverMac,
                                               closePrice,
                                               Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd")),
                                               额度分配Row1.分组
                                               );
                    //sb.Append(sql);
                    try
                    {
                        SQLHelper.ExecuteSql(sql);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                //sb.Append(" end;");
                //SQLHelper.ExecuteSql(sb.ToString());

                //更新日志表
                string         sqlLog = string.Empty;
                SqlParameter[] sqlParm;
                if (dtMac.Rows.Count > 0)
                {
                    sqlLog  = "update dbo.日志表 set 更新日期=@更新日期,更新数量=@更新数量 where 服务器MAC=@服务器MAC and 数据类型='委托'";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd"))), new SqlParameter("@更新数量", dtLimit.Rows.Count), new SqlParameter("@服务器MAC", serverMac) };
                }
                else
                {
                    sqlLog  = "insert into dbo.日志表(服务器MAC,更新数量,数据类型,更新日期)values(@服务器MAC,@更新数量,@数据类型,@更新日期)";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd"))), new SqlParameter("@更新数量", dtLimit.Rows.Count), new SqlParameter("@数据类型", "额度"), new SqlParameter("@服务器MAC", serverMac) };
                }

                SQLHelper.ExecuteSql(sqlLog, sqlParm);

                Program.logger.LogInfo(string.Format("额度分配数据入库结束:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
            }
            catch (Exception ex)
            {
                Program.logger.LogInfo(string.Format("额度分配数据入库异常:{0},当前server-{1}", ex.Message, serverMac));
                return(false);
            }
            return(true);
        }
Exemplo n.º 18
0
        public bool SendWTData(JyDataSet.已发委托DataTable dtWT, string serverMac)
        {
            try
            {
                if (dtWT.Rows.Count == 0)
                {
                    Program.logger.LogInfo(string.Format("接收server-{0}的已发委托DataTable.Rows=0", serverMac));
                    return(false);
                }
                JyDataSet.已发委托Row firstRow1 = dtWT[0];
                //判断当前MAC是否已经更新数据
                string    sqlMac = string.Format("select 更新日期 from dbo.日志表 where 服务器MAC='{0}' and 数据类型='委托'", serverMac);
                DataTable dtMac  = SQLHelper.ExecuteDt(sqlMac);
                if (dtMac.Rows.Count > 0)
                {
                    int cDate = Convert.ToInt32(firstRow1.日期.ToString("yyyyMMdd"));
                    if (cDate == Convert.ToInt32(dtMac.Rows[0]["更新日期"].ToString()))
                    {
                        string updateType = ConfigMain.GetConfigValue("UpdateType");
                        if ("0".Equals(updateType))
                        {
                            //删除原有server Mac的数据
                            string sqlDel = string.Format("delete from dbo.已发委托 where 服务器MAC='{0}' and 日期='{1}'", serverMac, firstRow1.日期.ToString("yyyyMMdd"));
                            SQLHelper.ExecuteSql(sqlDel);
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("begin ");
                Program.logger.LogInfo(string.Format("委托数据入库开始:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
                foreach (JyDataSet.已发委托Row 已发委托Row1 in dtWT)
                {
                    string sql = string.Format("insert into dbo.已发委托(日期,组合号,委托编号,交易员,状态说明,市场代码,证券代码,证券名称,买卖方向,成交价格,成交数量,委托价格,委托数量,撤单数量,服务器MAC)values('{0}','{1}','{2}','{3}','{4}',{5},'{6}','{7}',{8},'{9}',{10},{11},{12},{13},'{14}');",
                                               已发委托Row1.日期.ToString("yyyyMMdd"),
                                               已发委托Row1.组合号,
                                               已发委托Row1.委托编号,
                                               已发委托Row1.交易员,
                                               已发委托Row1.状态说明,
                                               已发委托Row1.市场代码,
                                               已发委托Row1.证券代码,
                                               已发委托Row1.证券名称,
                                               已发委托Row1.买卖方向,
                                               已发委托Row1.成交价格,
                                               已发委托Row1.成交数量,
                                               已发委托Row1.委托价格,
                                               已发委托Row1.委托数量,
                                               已发委托Row1.撤单数量,
                                               serverMac
                                               );
                    sb.Append(sql);
                }
                sb.Append(" end;");
                SQLHelper.ExecuteSql(sb.ToString());

                //更新日志表
                string         sqlLog = string.Empty;
                SqlParameter[] sqlParm;
                if (dtMac.Rows.Count > 0)
                {
                    sqlLog  = "update dbo.日志表 set 更新日期=@更新日期,更新数量=@更新数量 where 服务器MAC=@服务器MAC and 数据类型='委托'";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", Convert.ToInt32(firstRow1.日期.ToString("yyyyMMdd"))), new SqlParameter("@更新数量", dtWT.Rows.Count), new SqlParameter("@服务器MAC", serverMac) };
                }
                else
                {
                    sqlLog  = "insert into dbo.日志表(服务器MAC,更新数量,数据类型,更新日期)values(@服务器MAC,@更新数量,@数据类型,@更新日期)";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", Convert.ToInt32(firstRow1.日期.ToString("yyyyMMdd"))), new SqlParameter("@更新数量", dtWT.Rows.Count), new SqlParameter("@数据类型", "委托"), new SqlParameter("@服务器MAC", serverMac) };
                }

                SQLHelper.ExecuteSql(sqlLog, sqlParm);

                Program.logger.LogInfo(string.Format("委托数据入库结束:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
            }
            catch (Exception ex)
            {
                Program.logger.LogInfo(string.Format("委托数据入库异常:{0},当前server-{1}", ex.Message, serverMac));
                return(false);
            }
            return(true);
        }
Exemplo n.º 19
0
        public bool SendYJData(JyDataSet.业绩统计DataTable dtYJ, string serverMac)
        {
            try
            {
                if (dtYJ.Rows.Count == 0)
                {
                    Program.logger.LogInfo(string.Format("接收server-{0}的业绩统计DataTable.Rows=0", serverMac));
                    return(false);
                }
                JyDataSet.业绩统计Row firstRow1 = dtYJ[0];
                //判断当前MAC是否已经更新数据
                string    sqlMac = string.Format("select 更新日期 from dbo.日志表 where 服务器MAC='{0}' and 数据类型='业绩'", serverMac);
                DataTable dtMac  = SQLHelper.ExecuteDt(sqlMac);
                if (dtMac.Rows.Count > 0)
                {
                    if (firstRow1.日期 == Convert.ToInt32(dtMac.Rows[0]["更新日期"]))
                    {
                        string updateType = ConfigMain.GetConfigValue("UpdateType");
                        if ("0".Equals(updateType))
                        {
                            //删除原有server Mac的数据
                            string sqlDel = string.Format("delete from dbo.业绩统计 where 服务器MAC='{0}' and 日期={1}", serverMac, firstRow1.日期);
                            SQLHelper.ExecuteSql(sqlDel);
                        }
                    }
                }
                decimal closePrice;
                Dictionary <int, decimal> dictPrice = new Dictionary <int, decimal>();
                StringBuilder             sb        = new StringBuilder();
                sb.Append("begin ");
                Program.logger.LogInfo(string.Format("业绩数据入库开始:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
                foreach (JyDataSet.业绩统计Row 业绩统计Row1 in dtYJ)
                {
                    //string sql = "insert into 业绩统计(交易员,组合号,证券代码,证券名称,毛利,交易费用,净利润,买入数量,买入金额,买入均价,卖出数量,卖出金额,卖出均价)values(@交易员,@组合号,@证券代码,@证券名称,@毛利,@交易费用,@净利润,@买入数量,@买入金额,@买入均价,@卖出数量,@卖出金额,@卖出均价)";
                    //SqlParameter[] sqlParm = new SqlParameter[] { new SqlParameter("@交易员", 业绩统计Row1.交易员),new SqlParameter("@组合号", 业绩统计Row1.组合号), new SqlParameter("@证券代码", 业绩统计Row1.证券代码) ,
                    //new SqlParameter("@证券名称", 业绩统计Row1.证券名称), new SqlParameter("@毛利", 业绩统计Row1.毛利),new SqlParameter("@交易费用", 业绩统计Row1.交易费用),
                    //new SqlParameter("@净利润", 业绩统计Row1.净利润),new SqlParameter("@买入数量", 业绩统计Row1.买入数量),new SqlParameter("@买入金额", 业绩统计Row1.买入金额),new SqlParameter("@买入均价", 业绩统计Row1.买入均价),new SqlParameter("@卖出数量", 业绩统计Row1.卖出数量),
                    //new SqlParameter("@卖出金额", 业绩统计Row1.卖出金额),new SqlParameter("@卖出均价", 业绩统计Row1.卖出均价)};

                    //SQLHelper.ExecuteSql(sql, sqlParm);
                    int iCode = Convert.ToInt32(业绩统计Row1.证券代码.Trim());
                    if (dictPrice.ContainsKey(iCode))
                    {
                        closePrice = dictPrice[iCode];
                    }
                    else
                    {
                        closePrice = CommonUtils.GetClosePrice(业绩统计Row1.证券代码.Trim());
                    }
                    string sql = string.Format("insert into dbo.业绩统计(交易员,组合号,证券代码,证券名称,毛利,交易费用,净利润,买入数量,买入金额,买入均价,卖出数量,卖出金额,卖出均价,日期,交易额度,收盘价,分组,服务器MAC)values('{0}','{1}','{2}','{3}',{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},'{16}','{17}');",
                                               业绩统计Row1.交易员,
                                               业绩统计Row1.组合号,
                                               业绩统计Row1.证券代码,
                                               业绩统计Row1.证券名称,
                                               业绩统计Row1.毛利,
                                               业绩统计Row1.交易费用,
                                               业绩统计Row1.净利润,
                                               业绩统计Row1.买入数量,
                                               业绩统计Row1.买入金额,
                                               业绩统计Row1.买入均价,
                                               业绩统计Row1.卖出数量,
                                               业绩统计Row1.卖出金额,
                                               业绩统计Row1.卖出均价,
                                               业绩统计Row1.日期,
                                               业绩统计Row1.交易额度,
                                               closePrice,
                                               业绩统计Row1.分组,
                                               serverMac
                                               );
                    sb.Append(sql);
                }
                sb.Append(" end;");
                SQLHelper.ExecuteSql(sb.ToString());

                //更新日志表
                string         sqlLog = string.Empty;
                SqlParameter[] sqlParm;
                if (dtMac.Rows.Count > 0)
                {
                    sqlLog  = "update dbo.日志表 set 更新日期=@更新日期,更新数量=@更新数量 where 服务器MAC=@服务器MAC and 数据类型='业绩'";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", firstRow1.日期), new SqlParameter("@更新数量", dtYJ.Rows.Count), new SqlParameter("@服务器MAC", serverMac) };
                }
                else
                {
                    sqlLog  = "insert into dbo.日志表(服务器MAC,更新数量,数据类型,更新日期)values(@服务器MAC,@更新数量,@数据类型,@更新日期)";
                    sqlParm = new SqlParameter[] { new SqlParameter("@更新日期", firstRow1.日期), new SqlParameter("@更新数量", dtYJ.Rows.Count), new SqlParameter("@数据类型", "业绩"), new SqlParameter("@服务器MAC", serverMac) };
                }

                SQLHelper.ExecuteSql(sqlLog, sqlParm);

                Program.logger.LogInfo(string.Format("业绩数据入库结束:{0},当前server-{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), serverMac));
            }
            catch (Exception ex)
            {
                Program.logger.LogInfo(string.Format("业绩数据入库异常:{0},当前server-{1}", ex.Message, serverMac));
                return(false);
            }
            return(true);
        }
Exemplo n.º 20
0
        public static void OpenTreasureMenuEndFunction(FishingRod rod, int extra)
        {
            ModFishing.INSTANCE.Monitor.Log("Successfully replaced treasure", LogLevel.Trace);

            ConfigMain config             = ModFishing.INSTANCE.Config;
            SFarmer    lastUser           = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <SFarmer>(rod, "lastUser");
            int        clearWaterDistance = 5;

            if (config.OverrideFishing)
            {
                if (FishingRodOverrides.ClearWaterDistances.ContainsKey(lastUser))
                {
                    clearWaterDistance = FishingRodOverrides.ClearWaterDistances[lastUser];
                }
                else
                {
                    ModFishing.INSTANCE.Monitor.Log("The bobber bar was not replaced. Fishing might not be overridden by this mod", LogLevel.Warn);
                }
            }
            int whichFish   = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <int>(rod, "whichFish");
            int fishQuality = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <int>(rod, "fishQuality");

            lastUser.gainExperience(5, 10 * (clearWaterDistance + 1));
            rod.doneFishing(lastUser, true);
            lastUser.completelyStopAnimatingOrDoingAction();

            // REWARDS
            List <Item> rewards = new List <Item>();

            if (extra == 1)
            {
                rewards.Add(new StardewValley.Object(whichFish, 1, false, -1, fishQuality));
            }

            List <TreasureData> possibleLoot = new List <TreasureData>(config.PossibleLoot)
                                               .Where(treasure => treasure.IsValid(lastUser.FishingLevel, clearWaterDistance)).ToList();

            // Select rewards
            float chance = 1f;
            int   streak = FishHelper.GetStreak(lastUser);

            while (possibleLoot.Count > 0 && rewards.Count < config.MaxTreasureQuantity && Game1.random.NextDouble() <= chance)
            {
                TreasureData treasure = possibleLoot.Choose(Game1.random);

                int id = treasure.id + Game1.random.Next(treasure.idRange - 1);

                if (id == Objects.LOST_BOOK)
                {
                    if (lastUser.archaeologyFound == null || !lastUser.archaeologyFound.ContainsKey(102) || lastUser.archaeologyFound[102][0] >= 21)
                    {
                        continue;
                    }
                    Game1.showGlobalMessage("You found a lost book. The library has been expanded.");
                }

                int count = Game1.random.Next(treasure.minAmount, treasure.maxAmount);

                Item reward;
                if (treasure.meleeWeapon)
                {
                    reward = new MeleeWeapon(id);
                }
                else if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange)
                {
                    reward = new Ring(id);
                }
                else if (id >= 504 && id <= 513)
                {
                    reward = new Boots(id);
                }
                else
                {
                    reward = new StardewValley.Object(Vector2.Zero, id, count);
                }

                rewards.Add(reward);
                if (!config.AllowDuplicateLoot || !treasure.allowDuplicates)
                {
                    possibleLoot.Remove(treasure);
                }

                //rewards.Add(new StardewValley.Object(Vector2.Zero, Objects.BAIT, Game1.random.Next(10, 25)));
            }

            // Add bait if no rewards were selected. NOTE: This should never happen
            if (rewards.Count == 0)
            {
                ModFishing.INSTANCE.Monitor.Log("Could not find any valid loot for the treasure chest. Check your treasure.json?", LogLevel.Warn);
                rewards.Add(new StardewValley.Object(685, Game1.random.Next(2, 5) * 5, false, -1, 0));
            }

            // Show rewards GUI
            Game1.activeClickableMenu = new ItemGrabMenu(rewards);
            (Game1.activeClickableMenu as ItemGrabMenu).source = 3;
            lastUser.completelyStopAnimatingOrDoingAction();
        }
Exemplo n.º 21
0
        protected DataServantPrx GetDataServant()
        {
            try
            {
                lock (this)
                {
                    if (_dataServant != null)
                    {
                        _dataServant.ice_ping();
                        return(_dataServant);
                    }

                    if (_ic == null)
                    {
                        InitializationData icData = new InitializationData();
                        Ice.Properties     icProp = Util.createProperties();
                        icProp.setProperty("Ice.ACM.Client", "0");
                        icProp.setProperty("Ice.MessageSizeMax", "2097152");//2gb in kb
                        icData.properties = icProp;
                        Communicator ic = Util.initialize(icData);

                        if (ic != null)
                        {
                            _ic = ic;
                        }
                    }

                    if (_ic != null)
                    {
                        string         endpoint = string.Format("AASDataServer/DataServant:tcp -h {0} -p {1}", ConfigMain.GetConfigValue(BaseCommon.CONFIGIP), ConfigMain.GetConfigValue(BaseCommon.CONFIGICEPORT));
                        Ice.ObjectPrx  obj      = _ic.stringToProxy(endpoint);
                        DataServantPrx client   = DataServantPrxHelper.checkedCast(obj);
                        if (client == null)
                        {
                            LogHelper.Instance.Info("DataServerClient:无法获得有效数据服务器接口");
                            return(null);
                        }

                        client.ice_ping();
                        _dataServant = client;
                        return(_dataServant);
                    }
                }
            }
            catch (Ice.ConnectionRefusedException)
            {
                //计算机积极拒绝,认为未部署鱼头,不进行记录。
                //Program.logger.LogRunning("DataServerClient:数据服务器连接失败\r\n  {0}", ex.InnerException.Message);
            }
            catch (System.Exception ex)
            {
                _dataServant = null;
                LogHelper.Instance.Info("DataServerClient:数据服务器连接失败" + ex.Message);
            }

            return(null);
        }